Game Development Reference
In-Depth Information
Sprite animations
When it comes to sprites, there is another way of keeping things organized. It is much the
same as using groups; however, instead you are using an actual resource to group things to-
gether.
Let's say we have a set of walls. All are static (nonanimated) images but have different
looks to them. We could have all these different walls saved as separate sprites, or we could
put them all into one sprite as an animation. What this does is allow us to have all the non-
animated wall images in one resource as if it were a group.
When attaching this to an object, by default, it would play through every wall image as an
animation and would look a bit weird in the game. To avoid this, we need to stop the anim-
ation, and then pick which wall image we actually want to use. To achieve this, we can use
GML code or a drag and drop action to set the animation speed to 0 and stop the anima-
tion. However, we still have the issue of actually picking which image we want to show.
For this, GameMaker has a variable unique to each object called image_index . Each
frame of a sprite is referenced as a number from 0 upwards, 0 being the first frame of
every sprite resource. To choose which image we want to show, we just have to set the im-
age index, which can be done in GML or using a drag and drop action.
The image index of an object is separate to the animation speed. To actually stop the anim-
ation, we need to set another variable called image_speed to 0 . This stops the animation
from progressing through frames.
While this technique of organization may seem more complicated, it can actually make
code and game structure easier if used correctly. Whether this technique should be used de-
pends on the game being made.
Search WWH ::




Custom Search