GMS 2 How to detect moments in a animation sprite?

Suzaku

Member
Lets suppose that I have a object that represents a lady character:
upload_2019-5-27_18-20-26.png


and I have this animated sprite:
upload_2019-5-27_18-24-7.png

I want this character object to move a little to the right until it reach the frame 4 on that animation. Then the object must stop moving because the character will start to get up, following the animation. This is just a example but I want to do a lot of similar operations like that, where I need the object to behave differently accordly to the moment of the animation sprite.

My question is specificly about how to detect those moments where the object will do different things.

So in that example, should I keep monitoring the frames to execute a movement code whenever that sprite is between the frames zero and 4...... or should I divide the sprite into 2 sub sprites to detect those moments using the animation end event? Or is there another easy way to do such things? Thank you.
 

Attachments

Nux

Member
The way I would do it is to set the image_index of the object manually. So, you would begin to fall over and move your object to the right; during this you will slowly increment the image_index from 0 to 4. Once you reach the fourth index you would stop moving the object and begin the get up animation.

You could do this using an if-statement with a variable called "is_tripping", but a better way would be to use a state machine. You can find tutorials on state machines on youtube: https://www.youtube.com/watch?v=DYkJ91eg67Y
 
Top