yuribsl Posted October 25, 2017 Share Posted October 25, 2017 I'm new to phaser and i'm trying to fix problems with my animations. First i have an attack animation = player.animations.add('attack', [7,8,9,0], 8,false); if(controls.attack.isDown){ player.body.velocity.x = 0; player.animations.play('attack',7,false); } but the animations is playing on loop if i hold the attack button, i want it to play only once even if i keep holding the attack button. Also, if i dont hold the button the attack animation doesn't play until the end second i have a jumping animation and an idle animation player.animations.add('jumping', [3], 6, false); if (player.body.velocity.x == 0 && !controls.attack.isDown){ player.animations.play('idle'); } i think the idle animation is interfering with the jump, because when the player jumps the animation is the idle one, i would like to know how to play the jump animations on straight and diagonal jumps im stuck on this for some time now and couldnt find many answers on the web, if anybody can help me on this i will be grateful ^^ Link to comment Share on other sites More sharing options...
Cudabear Posted October 26, 2017 Share Posted October 26, 2017 For the first one, you're calling it every time through the update loop. You can use justPressed to prevent this https://photonstorm.github.io/phaser-ce/Phaser.Key.html#justPressed. if(controls.attack.isDown){ player.body.velocity.x = 0; if(controls.attack.justPressed) { //only play the animation if the user just pressed the key player.animations.play('attack', 7, false); } } For the second one, your idle animation is getting played every time your player sprite doesn't have x velocity. Since the jump is called whenever the user is jumping, I'd do something like this: if(!controls.attack.isDown){ if(player.body.touching.down){ //if we're on the ground, handle ground animations if(player.body.velocity.x === 0){ player.animations.play('idle'); } else { //walking animations???? } } else { //if we're in the air, we're obviously jumping or whatever player.animations.play('jumping'); } } Link to comment Share on other sites More sharing options...
Recommended Posts