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

[SOLVED] Animation resets, overlaps.

Discussion in 'Game Design, Development And Publishing' started by LoadingDevelopment, Nov 21, 2017.

  1. LoadingDevelopment

    LoadingDevelopment Member

    Joined:
    Sep 10, 2017
    Posts:
    313
    So this is the problem I am facing and I don't really know how to resolve it. :bash:
    I don't expect any straight answers on this, only ideas and opinions.

    I have a character with two animations, one is idle and one is with him shooting (Pointing his arm in the direction he has to shoot).
    I bet this problem is wildly encountered by newbies.
    Well, the problem is quite simple to understand, whenever I start to cycle through the shooting animation the idle animation stops, then when I stop pressing the shooting animation button the idle animation begins from frame 0. :confused:

    What I mean by that is that I don't know how to make continuous animation. o_O
    Whenever I press a button that changes the current idle animation it just resets.
    The problem explained in lesser words would be this, frames overlap.

    Here is the actual question (lol), what is the easiest way to make a sprite (animation) remember it's current frame and then return to it.
    I bet this is not easy but I know there are "easier" workarounds which I can't figure out apparently.

    I could list the ideas I have (like sectioning the whole character by the parts where the most animations happen) but I want to hear your opinion.
    And thank you for your time and response.
     
    Last edited: Nov 21, 2017
  2. inkBot

    inkBot Member

    Joined:
    Sep 15, 2016
    Posts:
    44
    Without seeing the actual code where you handle the animation, it sounds to me like you're having the animation playing be linked directly to the button being pressed. So it would stand to reason that when the button isn't pressed, the statement becomes false and the idle animation kicks in again. It could be solved by implementing a state machine, or simply adding a variable that would serve the same function.

    So instead of this pseudo code:
    Code:
    if (player presses button)
    { play shooting animation }
    
    You would have something more like
    Code:
    if (player presses button)
    { set player state to "shooting" }
    
    if (player state == "shooting")
    { play shooting animation }
    
    if ("shooting" animation is over)
    { set player state to "idle" }
    
     
    LoadingDevelopment likes this.
  3. LoadingDevelopment

    LoadingDevelopment Member

    Joined:
    Sep 10, 2017
    Posts:
    313
    Yes I have the animation linked directly to that button being pressed or not...

    This is great, I never thought of it like this. Using a variable as a "counter", as a third party state of the current animations that run.
    This way each time you cancel an animation the next one plays from start no matter what.
    Nice, very nice.:bunny:

    Well now I have another question which could be dumb.
    I expect the straight answer on this question because I simply don't know that function.
    How do I count if the animation is over or not? Is there a function that acts on frames individually?


    And now I realize I should have posted this topic on Programming...well sorry for that.
     
    Last edited: Nov 21, 2017
  4. inkBot

    inkBot Member

    Joined:
    Sep 15, 2016
    Posts:
    44
    To determine when the animation is over, first you'd need to know how long your animation is (shouldn't be much of an issue), and then use "image_index" to check against that number.
    Let's say your animation is 8 frames long, you'd want to check if image_index is greater than 7 (since animation frames start counting from 0).

    Code:
    if (image_index > 7)
    { set player state to "idle" }
    
    This is still pretty pseudo code-y, though.
     
    LoadingDevelopment likes this.
  5. LoadingDevelopment

    LoadingDevelopment Member

    Joined:
    Sep 10, 2017
    Posts:
    313
    @inkBot
    I don't know why I forgot "image_index" ohh gosh...
    I knew there is a "sprite_index" which sets the sprite of an obj but I forgot about "image_index" which counts the frames.

    Yea I know it's pseudo code-y, but I understand it very well...

    All I can say now is thank you for the helpful information in your first post.
    That has put my mind to work, which is always good, I thought how I could implement that "pseudo counter state variable" in many different ways and play with animations however I want to.

    So thank you again and I guess this thread could be marked as solved.
     
  6. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    828
    Read into finite state machines
     

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