phaser-swipe
A swipe component for Phaser.io
Install
You can grab the swipe.js file and include it in your project, or you can use npm or bower:
npm install phaser-swipe bower install phaser-swipe
Usage
You can use it in two ways. With or without a model. This is without model
var Swipe = ; // in create thisswipe = thisgame; // in update var direciton = thisswipe; if direction!==null // direction= { x: x, y: y, direction: direction }
This is with a model. Here you define your methods in your model. Only those methods defined will be used So if you do not want the diagonals, you can just omit those methods.
{ {} {} {} {} {} {} {} {} }; // in create thisswipe = thisgame yourmodel; // in update. The methods will only be called if you have a swipe. // point: { x: x, y: y } thisswipe;
Keyboard
The module will automatically understand all arrow keys for understanding up/down/left/right. If you use the model, it will call the methods for you. If you do not use a model, you will get a direction from check(), but in both ways you will not get a point for where it was pressed.
It understands the diagonals also, so pressing up and right will return DIRECTION_UP_RIGHT and call model.upRight() if it exists. Because two keys need to be pressed, the signal for a single key will not fire until it is released