• 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!

GameMaker How do i make a command execute when the animation gets on a certain frame?

T

Tyskaro

Guest
Hello everyone, i'm not so good in english, so forgive me if i make some mistake...

Recently i started learning how to programm and i was watching some tutorials, but sometimes i try alone doing something... And after trying for some time i made like 90% of what i was planning, that was an melee attack that sends a wave on the enemies and hits them... But, the wave spawns when i start the animation (The first frame), and i want it to spawn on the 7º frame...

if
{
instance_create_layer(x,y, layer, Aqua_1);

Combo = 0;
}

Basically the code makes a object (Aqua_1) that is the wave... So, the ideia is

if (The animation is on the 7º frame)

But i dont know whats the command for this... i tried Image_index... But it didnt worked (the code was written on a script... And i used sprite_index to set the animation for the Object)
 

Slyddar

Member
image_index is a decimal, so you need to be sure you are not using an equals when comparing it, unless you floor() it first.
So you can do :
Code:
if image_index >= 7 {
  //run your code
}
or :
Code:
if floor(image_index) == 7 {
  //run your code
}
But note that it may unintentionally run multiple times, as it will run whenever that condition is true. If you need a way to ensure it only runs once, usually you can use a flag for that, which is just a boolen variable that you set to false once it runs. So something like:
Code:
//create event
has_run = false;
Code:
//step event
if !has_run and floor(image_index) == 7 {
  has_run = true;
  //run your code
}
 

Rob

Member
You can also use the animation end event to make things happen at the end of an animation.
 

Yal

🐧 *penguin noises*
GMC Elder
The Animation End Event is my recommendation as well... if you don't have the "make things happen" point at the end of the animation, you can split the sprite into two different sprites and change sprites to the "after" part in the Animation End event.
 

Slyddar

Member
You can also use the animation end event to make things happen at the end of an animation.
Yeh, but I read it as he wanted something to happen at a particular frame of the animation, not at the end. Definitely the Animation End event is better if you want it at the end though.
 

Rob

Member
Yeh, but I read it as he wanted something to happen at a particular frame of the animation, not at the end. Definitely the Animation End event is better if you want it at the end though.
I could have sworn I saw him asking about how to make something happen at the end of the animation but re-reading it, he never uses those words so... I dunno :D If you want to make something happen before the end of the animation then yeah, the animation_end event isn't a good solution.
 
Last edited:
If you need a way to ensure it only runs once, usually you can use a flag for that, which is just a boolen variable that you set to false once it runs.
A simple 1 or 2 clicks alarm usually do wonders, too, without even needing to create another variable!
 

Yal

🐧 *penguin noises*
GMC Elder
I try to shy away from alarms and User Defined Events these days in favor of scripts and arrays when possible. Because if you have too many events in use, that object becomes a nightmare to edit. Can you see where the collision event with parent_damage is? Me neither.
1608423371290.png
 

Nidoking

Member
It's in the object's event list, under "Collision: parent_damage". You double-click that, and it takes you to the event tab. That, and close tabs that you're not using.
 
Top