'use strict'; var Protagonist = function(game, x, y) { Phaser.Sprite.call(this, game, x, y, 'protagonist'); this.alive = true; // Set the pivot point for this sprite to the center this.anchor.setTo(0.5, 0.5); // Enable physics on the missile this.game.physics.enable(this, Phaser.Physics.ARCADE); this.SPEED = 1000; // missile speed pixels/second }; Protagonist.prototype = Object.create(Phaser.Sprite.prototype); Protagonist.prototype.constructor = Protagonist; Protagonist.prototype.update = function() { // If the sprite is > 8px away from the pointer then let's move to it if (this.game.physics.arcade.distanceToPointer(this, this.game.input.activePointer) > 20) { // Make the object seek to the active pointer (mouse or touch). this.game.physics.arcade.moveToPointer(this, 1000); } else { // Otherwise turn off velocity because we're close enough to the pointer this.body.velocity.set(0); } }; module.exports = Protagonist;