mayfray Posted July 28, 2014 Share Posted July 28, 2014 Hi everyone, I've been playing with Phaser for a few months, but this is my first post. I'm currently using v. 2.0.6I know I'm probably missing something obvious here, but I'm trying to play a sprite animation based on the position of the mouse. The sprite is the the center of the screen and can hit projectiles coming toward it onClick. If the player clicks a projectile on the right side of the screen, I want the sprite to lift up its left arm (the sprite is facing you). Here is the code I wrote (which freezes the game onClick): if (game.input.activePointer.isDown) { if (activePointer.x > player.body.x) {player.animations.play('left');} else if (activePointer.x < player.body.x) {player.animations.play('right');} } else {player.animations.play('still');} I would really appreciate any advice you might have! Thanks! Link to comment Share on other sites More sharing options...
Heppell08 Posted July 28, 2014 Share Posted July 28, 2014 if(activePointer.x < game.world.width/2){ ... Left }if(activePointer.x > game.world.width/2){ ... Right } Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 If that's your code then the reason the game is 'freezing' is likely because activePointer is undefined. You need to call game.input.activePointer at all times unless you actually create a reference to it, like:var activePointer = game.input.activePointer;It's really beneficial to use the developer tools in your browser (usually opened by pressing F12) and checking the console for errors. Link to comment Share on other sites More sharing options...
mayfray Posted July 29, 2014 Author Share Posted July 29, 2014 If that's your code then the reason the game is 'freezing' is likely because activePointer is undefined. You need to call game.input.activePointer at all times unless you actually create a reference to it, like:var activePointer = game.input.activePointer;It's really beneficial to use the developer tools in your browser (usually opened by pressing F12) and checking the console for errors.Yes, that was the issue. It works now. Thanks so much!! Link to comment Share on other sites More sharing options...
Recommended Posts