1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 How to detect moments in a animation sprite?

Discussion in 'Programming' started by Suzaku, May 27, 2019.

  1. Suzaku

    Suzaku Member

    Joined:
    Jan 27, 2019
    Posts:
    51
    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.
     

    Attached Files:

  2. Nux

    Nux Member

    Joined:
    Jul 7, 2016
    Posts:
    372
    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
     
    Suzaku likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice