GML SOLVED! How do I make a sprite stop animating at a certain subimage?

A

anthropus

Guest
I SOLVEDIT!
change this
Code:
//hold last frame
if (image_index==5)
{
image_speed=0;
}
to this
Code:
//hold last frame
if (image_index>=5 &&& <6)
{
image_speed=0;
}
apparently image index returns a real number, not an integer
__________________________________
Hi all. Im using script-states (which are controlled by a switch statement) to control an object's sprites, behavior, etc, and all is pretty much working as I want it to atm, but im really struggling with making a sprite stop animating at a certain frame (subimage).

Basically, the last frame of a death animation has the character lying on the ground. So I want the death sprite animation to stop animating at that last frame [just to have a dead body laying there, which is later removed with an alarm with instance_destroy()]. But it seems no matter what code I try, the death sprite animation keeps looping (so the sprite and script-state are correct, but my "stop animation" code isnt working. Any help?

Here's the "Death" script-state
*the "hold last frame" part of the code is what is not working at all*
Code:
//set sprite
img_spd=.5;

sprite_index=sp_puny_death;
image_speed=img_spd;

//hold last frame
if (image_index==5)
{
image_speed=0;
}

//remove instance
if (alarm[1]=-1)
{
alarm[1]=2*room_speed;
}

scr_collision_enemy();
 
Last edited by a moderator:
S

SyntaxError

Guest
Try,
if image_index >= 5...

Actually, that probably wont work.

Instead use your own image index variable and manually increment it each step, checking it for if >= 5

Floating point errors...
 
A

anthropus

Guest
Try,
if image_index >= 5...

Actually, that probably wont work.

Instead use your own image index variable and manually increment it each step, checking it for if >= 5

Floating point errors...
but the sub images do not match up 1:1 with the steps. for example, in 5 steps of "time" there may have passed only 1 sub image. right?

floating point errors? thats above my noob level lol what is that? does that mean that game maker is making errors?
 
T

TheLady

Guest
but the sub images do not match up 1:1 with the steps. for example, in 5 steps of "time" there may have passed only 1 sub image. right?

floating point errors? thats above my noob level lol what is that? does that mean that game maker is making errors?
This is not a Game Maker error, it's a user error. A floating point basically means a decimal number, but the amount of numbers before/after the decimal is not a set amount. So, since image_index returns a Real, this is a decimal number and users tend to handle Reals (mistakenly) like an integer. You could try saying before your if statement:

var imageIndexRounded = floor(image_index);
if (imageIndexRounded == 5)
{
image_speed = 0;
}

I'm no Game Maker pro, but this should round whichever image index you are on down to an integer that you can check for. Hope this helps!
 
F

F_Clowder

Guest
I bumped into a useful animation resource on the Marketplace that deals with exactly your issue. I recommend you check out Animation Sequence.
 
Top