Jump to content

Sprite.animations.play() not working after collision?


Nebulocity
 Share

Recommended Posts

My game is a small platformer, where the player has to avoid enemies that drop down from the top of the "room", while performing the goal for the level.  My problem is that, after the enemies have dropped down, they do not change their animation sequence after touching a wall.  For instance, the top-most enemy in the screenshot below will eventually bump into the left wall.  When he does so, it will then start walking right (because I'm using game.physics.arcade.collide and enemy.body.bounce.x = 1).  However, I can't get the sprite's animation to change when this happens.

 

In the code below, I'm calling enemy.animations.play() to play the appropriate animation that should happen after the sprite is blocked on the left or right, but it's not working...the sprite changes direction as it should, and just continues to "moonwalk" as it marches across the screen  :P  Does anyone have an idea on why this would be happening, and what might be needed to fix it?  Thanks!

                // Change animation if enemy touches a wall		this.enemies.forEachAlive(function(enemy){                        // If the enemy is on the floor and was blocked on the left, make it walk right			if (enemy.body.onFloor() && enemy.body.blocked.left)			{				console.log('I was touched on the left!');				enemy.animations.play('right');			}                        // If the enemy is on the floor and was blocked on the right, make it walk left.			else if (enemy.body.onFloor() && enemy.body.blocked.right)			{				console.log('I was touched on the right!');				enemy.animations.play('left');			}			})

 4RdS0bw.png

Link to comment
Share on other sites

"Bump", but with some extra info:

 

I am still unable to determine why the sprite animation won't change.  However, when the game runs, I'm getting the text notification int he console log that the sprite did indeed touch the wall...  Any assistance would be greatly appreciated! 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...