Skip to content

JetLua/interaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

The interaction plugin for pixi.js

Resources

Stars

Watchers

Forks

Packages

No packages published