Code Monkey home page Code Monkey logo

interaction's Introduction

Interaction

npm version npm downloads

The interaction plugin for pixi.js.

Install

npm i @iro/interaction

Why Use It

  1. Unified event type, Pointer event only.
  2. Pointerout and Pointerupoutside have target value.

Usage

// webpack.config.js
plugins: [
  new webpack.ProvidePlugin({
    PIXI: 'pixi.js'
  })
]
import Interaction from '@iro/interaction'

// pixi.js@5
PIXI.Renderer.registerPlugin('interaction', Interaction)

// pixi.js@6
// remove default interaction extensions
for (const x in PIXI.extensions._queue) {
  for (const ext of PIXI.extensions._queue[x]) {
    if (ext.name === 'interaction') {
      PIXI.extensions.remove(ext)
    }
  }
}

// add @iro/interaction
PIXI.extensions.add(
  {
    name: 'interaction',
    ref: Interaction,
    type: [PIXI.ExtensionType.RendererPlugin, PIXI.ExtensionType.CanvasRendererPlugin]
  }
)

renderer.plugins.interaction.on('pointerdown', ev => {})
sprite.on('pointerup', ev => {})

/**
 * - tap
 * - pointerup
 * - pointerout
 * - pointermove
 * - pointerdown
 * - pointerenter
 * - pointerupoutside
*/

Support pointer-events like CSS

interface Sprite extends PIXI.Sprite {
  pointerEvents?: 'auto' | 'none'
}

const a: Sprite = new PIXI.Sprite(texture)
a.pointerEvents = 'none'

const b: Sprite = new PIXI.Sprite(texture)
b.interactive = true
b.on('pointerdown', console.log) // output

stage.addChild(b, a)

interaction's People

Contributors

dependabot[bot] avatar jetlua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ding-e turbopixi

interaction's Issues

Difference to the build-in interaction manager

I found your plugin via pixijs/pixijs#6509 (comment) and I am curious how it differs from the build-in interaction manager and what your plugin's purpose is.

I am asking because I am looking for an alternative way of handling interactions in PIXI. Unfortunately, their system completely breaks down as the number of display objects increases. So I am wondering if your plugin might be an alternative :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.