How do I move and stop an actor with animation for each state?
So you want to make your actor move left or right and have an animation when it does so. And you also want to animate your actor when it isn't moving and in the correct direction? Here you go. This is even compatible with jumping. Hooray!!! Now get to it!
The Setup
You only need one boolean attribute, game.FacingLeft, to determine if you are facing left or right.
You also need two boolean attributes, game.MoveLeft and game.MoveRight, to determine if you are moving left, right, or not at all.
Animation Moving Left
Taken from the platform template with some modifications, when you press left, you stop its motion (self.Motion.LinearX) since we are using the Accelerate behavior for movement(to be compatible for jumping logic). Give it an animation for whatever it does when moving left, and change the attribute that it is facing left, to true. Nothing needs to go into the 'Otherwise' part of the rule since we will handle this in the standing still Rule.
Animation Moving Right
Taken from the platform template with some modifications, when you press right, you stop its motion (self.Motion.LinearX) since we are using the Accelerate behavior for movement(to be compatible for jumping logic). Give it an animation for whatever it does when moving right, and change the attribute that it is facing left, to false.Nothing needs to go into the 'Otherwise' part of the rule since we will handle this in the standing still Rule.
Animation Standing Still
This one is a little more tricky. When you start your game it does not receive every event that a button is up. So instead of waiting for both buttons of left and right to be up to do a standing still animation, we will check that neither button is down and put all our logic in the 'Otherwise' section of the rule.
Again you want to stop any acceleration induced movement. Then depending on the value of self.FacingLeft, you change your image and/or add an Animate behavior with images corresponding to the correct direction.



