Legacy GM animating sprite sheets

Hello all when I am trying to animate using spr_index I either get results that when I press the right key the animation freezes then plays on release or the animation plays and player is stuck I have verified both the collision mask and the sprite origin but to no avail. heres one of the code variations I tried

if(xprevious<x)
{
image_index=0;
sprite_index= run_test;
image_xscale=1;
image_speed=1}


if(xprevious>x)
{
image_index=0;
sprite_index= run_test;
image_xscale=-1;
}
 

shortbread

Member
You're resetting the image_index to 0 every time the object moves, which is why the animation is frozen when moving.

If you want to reset the animation to the first frame when you start moving, place the image_index = 0; into a keyboard_pressed event so that it only executes on the initial press and doesn't keep setting the index to 0 while being held.

You can also move all your existing statements into the same event.

For example:
Code:
if (keyboard_check_pressed(vk_right)) {
   image_index = 0;
   sprite_index = run_test;
   image_xscale = 1;
   image_speed = 1;
}
 
thanks I added the code your provided to a step event and the run animation does not stop and the player is stuck in place any thoughts where I may have missteped?
 

shortbread

Member
To stop the animation try this:
Code:
if (xprevious == x) {
image_index = 0;
image_speed = 0;
}
This will check is your player has NOT moved since the last step and stop the animation.
In terms of collisions thats a whole other situation, I'd recommend you look at some tutorials on youtube for collisions etc.
 
Top