• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Animation resets, overlaps.

AriesGames

Member
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 by a moderator:
I

inkBot

Guest
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" }
 

AriesGames

Member
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" }
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 by a moderator:
I

inkBot

Guest
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.
 

AriesGames

Member
@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.
 
Top