@iro/interaction

1.3.0 • Public • Published

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
*/

Supports PointerEvents 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)

Package Sidebar

Install

npm i @iro/interaction

Weekly Downloads

3

Version

1.3.0

License

MIT

Unpacked Size

38.6 kB

Total Files

6

Last publish

Collaborators

  • jetlua