[Solved, there is no easy way] How to code ping-pong animation the easy way

T

trentallain

Guest
I've read this thread
https://forum.yoyogames.com/index.php?threads/sprite-ping-pong-setting-bug.38029/

I was introduced to the idea of ping-pong animation when importing sprites

Is there an easy way to code ping-pong animation? Such as function or built-in variable?
Create a variable that stores the current frame of animation.
Each step increase this until it reaches the end of your sub images. And then decrease that variable until it reaches 0. Repeat.

And then you can draw your sprite and set the image index as that variable.
 

TsukaYuriko

☄️
Forum Staff
Moderator
No, you won't find this in the built-in functionality.

What you can do is take manual control over drawing. Define your own equivalents of animation-related variables, as well as a boolean that keeps track of whether the animation is currently playing forward or backwards.

Depending on said boolean, let the animation play in the correct direction. If the frame either reaches or exceeds the maximum frame number, or reaches or sinks below 0, flip the boolean.
 

Sabnock

Member
i thought GMS2 had this as a built function you can apply when in the sprite editor along with the speed of the animation?
 

Sabnock

Member
CREATE EVENT
Code:
can_step = true;
aspd = 1;
STEP EVENT
Code:
if (can_step) {
    image_index += aspd;
    can_step = false;
    alarm[0] = 5;

    if (image_index == image_number - 1 || image_index == 0) aspd *= -1;
}
ALARM[0] EVENT
Code:
can_step = true;
 

pipebkOT

Member
ping pong- animation means playing the animation back and forth in a loop? :confused: im confused, aside that


why not just copy and duplicate all the frames of the animation, and then sort the duplicated frames backwards in the sprite editor. i remember that gms 1.4 did this for you in the animation menu "add reverse" feature. but they don't have this feature in gms2 :( so you have to do it manually

sure, it will cost unnessesary memory space, but its the easy way if you don't want to code
 
Last edited:
Top