matt-hayward / olcPGEX_AnimatedSprite

Easily use animated sprites in the OLC Pixel Game Engine
22 stars 4 forks source link

Adding support for PingPong playback #15

Closed 0xnicholasc closed 4 years ago

0xnicholasc commented 4 years ago

Added the concept of PLAY_MODE. FORWARD is the default/original behavior. PING_PONG plays the frames forwards, then backwards, then forward again, etc...

I also moved the member variable declarations above the prototypes so that function prototypes can use the enums

matt-hayward commented 4 years ago

I'm not sure what a valid use case for this is. Can you give an example, please?

0xnicholasc commented 4 years ago

I'm not sure what a valid use case for this is. Can you give an example, please?

It is useful when you have an animation that is a mirror image of itself on the center frame. Consider this simple 3-frame walking animation.

3-frame-walk

Ping-pong mode allows me to avoid defining it as a 4 frame animation. In situations with larger number of frames it saves even more work.

[Edit]If you think of an oscillating action like the swing of a pendulum, it applies there as well. You only need frames for the swing in one direction. Once it reaches the apex on one side, the animation will reverse until it reaches the other side's apex, and reverse again.

It's a pretty common feature in different animation software and game engines. I actually added it because I needed it for my use-case.

matt-hayward commented 4 years ago

Sorry it's taken me a while to get back to you on this.

With the release of PGE2, I plan to do an extensive rewrite of this PGEX to add support for some of the features that PGE2 offers.

As part of that, I will likely add in the ping-pong feature, so for now I'm going to close this PR.