0.2.2 • Published 10 years ago

pixi-simple-gesture v0.2.2

Weekly downloads
36
License
MIT
Repository
github
Last release
10 years ago

pixi-simple-gesture

Add Pinch, Pan, Tap gesture support to pixi.js sprites.

npm install --save pixi-simple-gesture

Usage

Pinch

var gesture = require('pixi-simple-gesture')

var sprite = new PIXI.Sprite(texture)
gesture.pinchable(sprite)

sprite.on('pinchstart', function() {
  console.log('pinch start')
})

sprite.on('pinchmove', function(event) {
  console.log('pinch move', event)
})

sprite.on('pinchend', function() {
  console.log('pinch end')
})

The 'pinchmove' handler receives an event object containing the following properties.

NameValue
scaleScaling that has been done
velocityVelocity in px/ms
centerCenter position for multi-touch
dataOriginal InteractionData from pixi.js

Pan

var gesture = require('pixi-simple-gesture')

var sprite = new PIXI.Sprite(texture)
gesture.panable(sprite)

sprite.on('panstart', function() {
  console.log('pan start')
})

sprite.on('panmove', function(event) {
  console.log('pan move', event)
})

sprite.on('panend', function() {
  console.log('pan end')
})

The 'panmove' handler receives an event object containing the following properties.

NameValue
deltaXMovement of the X axis
deltaYMovement of the Y axis
velocityVelocity in px/ms
dataOriginal InteractionData from pixi.js

Tap

var gesture = require('pixi-simple-gesture')

var sprite = new PIXI.Sprite(texture)
gesture.tappable(sprite)

sprite.on('simpletap', function() {
  console.log('simply tapped')
})

NOT 'tap', simpletap. Because 'tap' is already used by pixi.js. This 'simpletap' works a bit better with 'pinch' and 'pan'. The Handler receives an event object containing the following properties.

NameValue
dataOriginal InteractionData from pixi.js

Note

Any requests, issues, PRs are welcome!

TODO

  • Add Inertia Mode
  • Add Complex? Tap, emits 'tapstart', 'tapcancel', 'tapend'. Could be useful to implement UI components which has active state style.
0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago