• Content Count

  • Joined

  • Last visited

  1. Yeah, that nearly fixes it though it only displays the attack animation for a split second and then returns to the idle animation. I have fixed this by giving the player a canAttack flag and an attackTimer that determines when the player can attack again but this feels hack-y. var canAttack = true;var attackTimer = 0;if(this.attackButton.isPressed()){ if(canAttack){'attack'); canAttack = false; attackTimer = + 300; } } else if (this.dpad.left.isDown) { this.sprite.body.velocity.x = -this.maxVelocityX; if(canAttack){ //allows attacking while moving'run'); } this.facing = 'left';} else if (this.dpad.right.isDown) { this.sprite.body.velocity.x = this.maxVelocityX; if(canAttack){'run'); } this.facing = 'right';} else { if(canAttack && > attackTimer){'idle'); }}I've tried placing a check in the update for when the sprite.animations.isFinished it set's the canAttack flag back to true, but for some reason this does not work nor does storing the attack animation and then checking whether it isFinished. In both cases isFinished is undefined? if(this.sprite.animations.isFinished){ //play idle animation}console.log(this.sprite.animations.isFinished); //'undefined'//attack(){ var attackAnim ='attack');//}//update(){ if(attackAnim.isFinished){ //play idle animation } console.log(attackAnim.isFinished); //'undefined'//}And I've tried accessing the currentAnim and checking whether it isFinished but it doesn't work either.
  2. Hi, I've been using Phaser for about a month now and I'm really enjoying it so far. I've just recently came up with a problem that I'm not able to find a solution to with any of my searches. I have a basic player character that moves and plays a run animation when I press left or right on the arrow keys. The animations play perfectly and loop like they are supposed to. However I am trying to add an attacking animation, that plays when the player presses the space bar for example, but it doesn't play through the entire animation like my run animation does. It is stuck on the first frame for as long as I hold the attack key. Furthermore if I change the movement code that moves the player right when the right arrow key is pressed to instead play the attack animation instead of the run animation it plays through correctly. Are the left and right cursor input keys treated differently than other keys whereas the left and right arrow keys are continuously 'fired' off and other keys send just one signal? In my player's preload function I create my sprite and add a few animations to it. I have the attack animation set to not loop. I thought this may have had something to do with my problem, but changing it to loop does nothing. this.sprite =, 64, 'playerSprites');this.sprite.animations.add('idle', [0, 1, 2, 3], 4, true);this.sprite.animations.add('run', [8, 9, 10, 11], 8, true);this.sprite.animations.add('attack', [16, 17], 4, false);In my players create function I set up the cursor keys and the spacebar. this.dpad =;this.attackButton =;In the players update function I check my input and change animations accordingly. if (this.dpad.left.isDown) { this.sprite.body.velocity.x = -this.maxVelocityX;'run'); this.facing = 'left';}elseif (this.dpad.right.isDown) { this.sprite.body.velocity.x = this.maxVelocityX;'run'); //If I change this to play the 'attack' animation it loops correctly this.facing = 'right';}else{'idle');}if(this.attackButton.isDown){'attack'); //When I press the spacebar it only displays the first //frame of the attack animation no matter how long I hold the key.}If anyone has any insight on what is going on here I would greatly appreciate the help. =)