GameMaker How to synchronize animation and object movement?

Suzaku

Member
Assuming that its a platform game, how to synchronize the object movement of the character(with its particular object speed and movement) and its animation?
(lets please take the example below).


Im thiking about some ways to do that:
1. timelines(I dont really like them),
2. split the sprite into 3 sprites(or how much we need) and then using a script running in the step event, verifying for the condition(like vspeed<0) to change to the next sprite, if condition is false it will just freeze the animation with image_speed=0 or change to a special sprite that is a loop, and keep it like that until condition is true, then it changes to the next sprite.
3. animation end event with split sprites.

Any other method or tips? Thank you.
 

YoSniper

Member
I recommend setting the object's image_speed to zero.

Then you can choose the image_index of your sprite depending on the object's current vspeed (or however else you track your speed.)

For example:
Code:
if vspeed < 0 { //Jumping up
    if image_index < 2 {
        image_index += 0.25; //Value can vary
    }
} else { //Halting in air and falling
    if image_index < 6 {
        image_index += 0.25; //Value can vary
    }
}
Also note that the above would only work for the posted sprite. If you change the sprite_index based on whether the player is grounded, running, etc., then you would need to have conditions surrounding code like the above to account for each case.
 
Top