Hi,
I recently discovered GDevelop and its potential but I’m facing a issue:
I have a object which have some animations set to it.
When I click somewhere on the screen, a fire animation should play. If I stay clicked, the animation is repeated multiple times in a loop. But in order to keep the animation smooth, I need the animation to finish its loop before being switched back to the idle animation. So, theoretically, if I click the mouse for 1 frame, the animation should play all its 8 frames and go back to the idle position without hiccups…
But I don’t know how to do that. I tired to set up timers and a while loop but it doesn’t work, it makes the animation unable to play. I don’t really understand the logic of the event editor, I’m more used to actually script stuff (python 3) but I have no knowledge in JS, so…
The last thing I tried was this:
But it doesn’t work:
When I click once, the animation is played in a infinite loop. If I click a second time, it stops. If I click a third time, the animation starts but stops as soon as I stop to hold down the click, and jumps back to the idle animation…
Can you help me ?
I see much wrong stuff here. First why do you use a variable, you can directly use the animation expression to get the animation being played. I will mirror what I mean in python to make it easier for you to understand:
Using a variable here is like doing
if sprite.animation == 1:
condition = True
else:
condition = False
if condition:
# rest of the code
pass
Your entiere code looks also wrong. Look at this Python transcript:
# by default fire_annimation is false
timer = rambo_gedeon.get_timers()["fire_annimation_timer"]
if mouse.pressed():
rambo_gedeon.set_anim(1)
fire_annimation = True
if mouse.released() and scene.get_timers()["fire_annimation_timer"].running_since_at_least(0.3):
timer.run()
rambo_gedeon.set_anim(0)
fire_annimation = False
if fire_annimation:
timer.run()
rambo_gedeon.unpause_anim()
Now the correct python code would be:
#animation is not set on looping
if mouse.pressed():
rambo_gedeon.setAnim(1)
if rambo_gedeon.anim_finished() and rambo_gedeon.anim == 1:
# replay the anim
rambo_gedeon.setAnim(1)
# if the mouse is no more pressed change the anim back to idle
if not mouse.pressed():
rambo_gedeon.setAnim(0)
No need for timers here, so I threw them out. I can first reset the anim and then change it back to 1 without hiccups as the event sheet is entirely executed before drawing each frame. Now it’s up to you to translate the python back to events
Thanks for your explanations with Python syntax. I really appreciate it. Makes me think that I should take notes, it would be easier than just guessing, it just makes the thing even more messed up.
While writing this answer, I realized there’s a “finished animation” condition. I feel stupid now. lol
1 Like
There is no problem in not knowing every single action and condition. Did you ever learn a library’s documentation and learn it to know the entire API? Nobody does that and that’s normal. Don’t hesitate to mention me (@arthuro555) if you have an issue again
1 Like