• 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 Issue with Changing Sprites

Wonsubon

Member
I have an object for the player with a script for the free state (there will be more scripts for other actions), and in the free state script it includes jumping, walking, crouching, and idle animations. For changing animations, I change the sprite index depending on the situation. The second longest animation is the idle itself at 16 frames, and the longest animation is one of the three possible idles to play sitting at 24 frames. Whenever an idle animation finishes playing, it returns back to the idle, and this applies to all but the one that is 24 frames long. Instead, that one seems to cap at the image index 15, the last frame of the idle, and it simply repeats the animation from the index 0 to 15 until you interrupt it by moving. Would I have accidentally written something in the code that makes it cap at 15, or is this a "natural" issue that has a method to fix so that the 24 frame idle goes through and finishes to return back to idle?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Are you setting the sprite_index and the image_index? How are you drawing the sprite? Do you use custom variables for the sprites or anything related to drawing?
 

ZELPAD

Member
I use Alarms to time the Anamation.
Test it with a Alarm of 24 for your Animation. And than change the Sprite to what you want.
 

Wonsubon

Member
Are you setting the sprite_index and the image_index? How are you drawing the sprite? Do you use custom variables for the sprites or anything related to drawing?
The sprite is drawn normally, I have no shaders or draw event for it. I have each sprite_index set in its own variable in the create event and the script references the variables. The image_index is reset back to 0 in another script executed at the end of the free state script which checks if the current sprite_index is or is not equal to what the last_sprite variable is which simply stores what sprite it was the step prior (this code is put in a separate script because other objects will reference it). Any other time the image_index is referenced is to check if an animation has reached its last image_index for ones that do not loop such as the animations for crouching down and skidding after running for a set amount of time
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The sprite_index and the image_index are intimately linked, and how you DRAW the sprite is important. What is drawing it normally? If it's not draw_self() or using the actual sprite_index like this, then it's not normally:
draw_sprite_ext(sprite_index, image_index, x, y, etc...)

This is why I asked how you are drawing the sprite and why this makes me think you are not setting the sprite_index, but instead drawing using variables:
I have each sprite_index set in its own variable in the create event and the script references the variables.
 

Wonsubon

Member
The sprite_index and the image_index are intimately linked, and how you DRAW the sprite is important. What is drawing it normally? If it's not draw_self() or using the actual sprite_index like this, then it's not normally:
draw_sprite_ext(sprite_index, image_index, x, y, etc...)

This is why I asked how you are drawing the sprite and why this makes me think you are not setting the sprite_index, but instead drawing using variables:
Just double checked, the sprite is drawn with draw_self(). An example of how I am changing the sprite index is sprite_index = sprite_run, with the create event having the variable sprite_run = spr_playerRun which is the sprite
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
OKay, in that case, I'd start using the debugger. You want to add breakpoints to the points in the code where you are setting the image_index/sprite_index aand then check the values, and you can step through the code a line at a time to see what is changing the values. You can also add the image_index and sprite_index values into the "watches" window and see how they change over time as the game progresses.
 
Top