Tutorial
Page 5 of 10
Changing Animation Sets
When working with bitmap sprites, you would normally change the sprite_index to change the sprite to reflect an action in your game, like picking something up or jumping. However, skeletal animation
sprites have all this information stored within the JSON in the form of animation sets. So how do we change these to show different actions? Well, we simply use the function mentioned previously to set the animation
again at the appropriate point.
Open up the object "oPlayer" if it's not already open and add a Key Pressed Event for the <Space> key. Drag a "Code" action into the event and write the following:
We are checking the current animation to see if the player is jumping, and if he is not then we set the animation to show the "jump" set. As you can see, we use the skeleton_* functions just as we would
the sprite_* functions to change things.
Now, we have the player jumping, but we also need to have it start running again when the jump is over. We could code this ourselves, checking the current image_index against the
image_number in the Step Event, but there is no need as GameMaker: Studio has a special event that is triggered only on the last frame of any animated sprite (whether it be
bitmap or Spine) called the Animation End Event.
Add this to our player object now (you can find it in the Other events category) and type the following code:
As you can see, we are doing the exact same check as before, only now we look for the "jump" animation and change the sprite back to "run". You can test the game now and see that pressing <Space> does
indeed change the animation.
© Copyright YoYo Games Ltd. 2014 All Rights Reserved