Quote: "First, I can see that you use floats for start and end frames, I think integers are what is supposed to be there as you can't start frame "2 and a half" (2.5), they have to be whole."
Yep, integer for frames. Good call Cybermind.
Not trying to wrap my head around your code, but I ran into this starting out playing animations and here was what was going on in my code...
It will play the animation each cycle of the main loop when the conditions are met, so it will keep starting it over and over which keeps it at frame 1.
My solution was to check the usual conditions for input, then before playing the animation I also check to see if it is playing already.
That prevents it from starting again if it is already playing, and then it only starts over if it has reached the end like it is supposed to, rather than starting frame 1 every cycle of the main loop.
There are several ways to do that.
One way is like mentioned above having a variable for a flag, then there are also some commands that will check animation states.
Here is a snippet of a pair of layers animating with only two frames, so I just check the frame it is on...
...
// check for inputs
if GetRawKeyState( 38 ) //up
SetSpriteFrame(character_selected,2)
//CHECK TO SEE IF IT IS ALREADY ANIMATING AND PLAY IF NOT
if GetSpriteCurrentFrame( 1 ) <> 6 and GetSpriteCurrentFrame( 1 ) <> 7
PlaySprite( 1, 6, 1, 6, 7 )
endif
if GetSpriteCurrentFrame( 2 ) <> 6 and GetSpriteCurrentFrame( 2 ) <> 7
PlaySprite( 2, 3, 1, 6, 7 )
endif
elseif GetRawKeyState( 37 ) //left
SetSpriteFrame(character_selected,4)
//CHECK TO SEE IF IT IS ALREADY ANIMATING AND PLAY IF NOT
if GetSpriteCurrentFrame( 1 ) <> 3 and GetSpriteCurrentFrame( 1 ) <> 4
PlaySprite( 1, 6, 1, 3, 4 )
endif
if GetSpriteCurrentFrame( 2 ) <> 3 and GetSpriteCurrentFrame( 2 ) <> 4
PlaySprite( 2, 3, 1, 3, 4 )
endif
elseif ...
Usually you will have more frames than just two for sprites, but I think you will get the idea.
These sprites have more animations that were loaded from the same sprite sheet, so those are the two frames I need to make sure it was not on already to know that this animation was not already playing.
Probably could have just checked one sprite, since the layers work together, but I checked both just to be thorough, and to be easier for me when looking back at it later.
Which would have looked like this...
...
//CHECK TO SEE IF IT IS ALREADY ANIMATING AND PLAY IF NOT
if GetSpriteCurrentFrame( 1 ) <> 6 and GetSpriteCurrentFrame( 1 ) <> 7
PlaySprite( 1, 6, 1, 6, 7 )
PlaySprite( 2, 3, 1, 6, 7 )
endif
...
These layers were for legs and body movement for a cartoon style animation, so the legs were twice the speed as the body.
The head was a separate layer with a single frame for the direction. ( SetSpriteFrame(character_selected,2) )
This was a snippet to allow me to preview different characters as I was creating them, hence the character_selected variable.
Only the heads were different, with the legs and body sprites being shared, and made in a base white with code to change the colors depending on the character selected.
You could easily change this to check for a range of frames for any length animation instead of just the two by using the > and < instead of <>.
Anyway, making sure that the animation is not already playing before playing it will ensure that the continual 1st frame issue won't happen.
I hope this helps.
Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1