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

GML Visual Play sprite animation once in game

1

1R85

Guest
In the sprite maker one can toggle between "loop" or "ping-pong",
but why are there not a "play once" option? Or play x times - where one can change the number of times.

With DND: How do I make a sprite only play once inside the game?
 
I'm not that familiar with DND, but there should be an event called Animation End. In this, set image_speed to 0. You could also set image_index to 0 if you wanted your sprite to return to its first sub-image after playing.
 

rIKmAN

Member
In the sprite maker one can toggle between "loop" or "ping-pong",
but why are there not a "play once" option? Or play x times - where one can change the number of times.
Those options are only to preview the animation, they aren't settings you can choose to have the sprite behave in that way when the game is run.
 
1

1R85

Guest
I'm not that familiar with DND, but there should be an event called Animation End. In this, set image_speed to 0. You could also set image_index to 0 if you wanted your sprite to return to its first sub-image after playing.
Thank you for the suggestion!
But I can't seem to figure out how to make an Animation End event with DND. When I search the DND options I don't get any hits.
Anyone?

Those options are only to preview the animation, they aren't settings you can choose to have the sprite behave in that way when the game is run.
Oh. How do one make the animation ping-pong with DND?
 

pipebkOT

Member
@1R85
its called Animation End event, Its and EVENT ,NOT and drag n drop action.

its on add event >> other >> animation end

in this event you put the code that checks if the sprite index equals to the sprite that you don't want to loop and set an action.
example

Code:
if sprite_index==sp_player_attack
{
sprite_index=sp_player_idle
image_speed=0.3
}
in this example, when the attack animation has ended, the player sprite is set to idle.





to do a ping pong animation you could just duplicate the sprites of the animation and then sort them in reverse in the sprite editor.
so you have like in example

5 animation frames
+5 duplicated frames in reverse.


or just put image_speed*=-1 in the animation end event
 
Last edited:
1

1R85

Guest
its called Animation End event, Its and EVENT ,NOT and drag n drop action.

its on add event >> other >> animation end
Thanks!
Well, I found:
Object > Events > Add event > Other > Animation End

Here I can put DND - or code I guess.

But:
Can I do this with DND - and if so - how?
And if I must code it: How do I add code here? (I hoped I could make games with DND only.. I am not a coder.)
 

JackTurbo

Member
As others have said image_speed controls the animation playback. 1 is normal speed play back -1 is normal speed but reverse. So multiplying the current speed by minus one will reverse it.

image_speed = image_speed * -1;

Can't really help with dnd never used it
 

pipebkOT

Member
@1R85
you have two options,


1 you add a code block only for this time since you don't want to code, with the drag n drop action "execute code"
and paste the code there. which will take you like 10 seconds

2 you do it all in drag n drop with is more tedious, since you have to search for every action.

in both, drag and drop and gml you need to know about coding, and believe me that gml is far more easy, fastest and clean looking than drag and drop.


here is the code you need in gml

Code:
if sprite_index==sp_player_attack   ///or whatever sprite that you don't want to loop
{
sprite_index=sp_player_idle
image_speed=0.3
but all this depends on what are your needs ,since i don't know if you want to change the sprite after the animation has ended, or if you simply want the animation to stop.


if you want to do it in drag and drop, you would need a "if variable" action, a "set sprite" action , and a "set speed" action,
then use the logic to understand what you need to do to fit your needs


as you see, using drag and drop doesn't guarantee you that you will not need to learn how to code, you in need should learn how to code, how if statements works, how variables work, and what are the built in variables of an object, like image_speed, image_index, sprite_index, etc
 
Last edited:
1

1R85

Guest
@JackTurbo and @pipebkOT

Thank you both for your helpful suggestions!
Woopdeedoo it finally works! :)

It turned out it was not that much work to do this in DND:
Object > Events > Add event > Other > Animation End > (DND)
Set animation (self) speed -1
Destroy Instans (self)

Without the "Destroy instans" the animation would play once and then show the first frame of the animation.
(DND that was done before this was that if the main character touched a special type of enemy an animation would play out.)
 
Top