Phaser plugin to move an object and stop it at an exact position
npm install phaser-move-and-stop-pluginmoveToXY to have the displayed object stop when the x/y position is reached.
bash
$ npm install phaser-move-and-stop-plugin
`
Usage
First add the plugin to game in your main create() function of your phaser state:
`javascript
import MoveAndStopPlugin from "phaser-move-and-stop-plugin";
export default game => ({
create: () => {
game.moveAndStop = game.plugins.add(MoveAndStopPlugin);
},
update: () => {
//...
}
});
`
Then call one the the following api:
API
$3
It it same as phaserJS moveToXY except that the object will stop at the exact x/y position.
#### Arguments
* [displayObject(state, [ownProps]): any]: The display object to move.
* [x: number]: The x coordinate to reach.
* [y: number]: The y coordinate to reach.
* [speed: number (optional)]: The speed it will move, in pixels per second (default is 60 pixels/sec)
* [maxTime: number (optional)]: Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
* [events: object (optional)]: List of events to trigger.
#### Example
`javascript
game.moveAndStop.toXY(item, x, y, 5000, null, {
onStopped: () => {
console.log('stopped before reaching position!');
},
onPositionReached: () => {
console.log('position reached!');
}
});
`
$3
It it same as phaserJS moveToObject except that the object will stop at the exact destination position.
#### Arguments
* [displayObject(state, [ownProps]): any]: The display object to move.
* [destination: any]: The display object to move towards. Can be any object but must have visible x/y properties.
* [speed: number (optional)]: The speed it will move, in pixels per second (default is 60 pixels/sec)
* [maxTime: number (optional)]: Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
* [events: object (optional)]: List of events to trigger.
#### Example
`javascript
game.moveAndStop.toObject(item, dest, 5000, null, {
onPositionReached: () => {
console.log('position reached!');
}
});
`
$3
Stop the object
$3
return true` is the object is moving