AnimImage: anims, rotations, squash/stretch

Monkey Forums/Monkey Code/AnimImage: anims, rotations, squash/stretch

Raph(Posted 2014) [#1]
Edit: now on version 3, see rest of thread.

I whipped this up today because I was tired of writing update code over and over. It's a container for regular Image animation strips and for arrays of images, that effectively extends them with the following:

- fire and forget cycling animations. You can set these to forward, back, or pingpong, define the start and end frames, set the speed, and it'll take care of everything for you.

- You can also invoke a "PlayOnce" -- actually, "play specific number of times."

- similarly, fire and forget rotation. If you need stuff spinning on screen, or want to have things have just a little bobble to them, you can set a min and max rotation angle, and a number of degrees per second, and whether to go clockwise, counterclockwise, or pingpong.

- squash and stretch for movement. You set a vector value, and an "intensity" value, and the object will deform in the proper orientation. Right now, I have it also automatically set the object to spinning based on the vector if rotation is turned on, but I should probably make that optional.

- it works with either animstrips loaded the usual Monkey way, or with arrays of images you build yourself (say from an atlas) and pass in.

Demo is here:
http://www.raphkoster.com/monkey/animimage/MonkeyGame.html

Caveats:

- barely tested, haven't actually tried most of the functionality yet

- it updates in the draw loop so you don't have to write your own update and maintain a list. This means you can mostly just swap out any DrawImage and LoadImage for DrawAnimImage and LoadAnimImage. Even stuff like WritePixels etc should work.

- I do compensate for time elapsed between OnRenders, skip frames if needed, etc, but I haven't tested it with crappy framerates.

- I would have extended Image to make this work more cleanly, but I can't cast an Image to an AnimImage (see http://www.monkey-x.com/Community/posts.php?topic=5236) and I can't clone an Image because a bunch of it is Private...

Fixes, comments, & thoughts all welcome...




Raph(Posted 2014) [#2]
Oh, the test code calls for two images -- one that's 8 frames (demo uses a spinning ball) and one that is just a 64x64 ball or something to show the squash/stretch. Sorry, forgot to comment it out.


Raph(Posted 2014) [#3]
Changes:

- Now has wrappers for all the Image methods.
- You can now point many AnimImages at one Image instead of loading one per AnimImage (doh)
- Now supports a PlayOnce method and a RotateOnce method. Both actually support multiple plays, not just play once. They don't remember previous state, though, you'll have to set that up yourself.

New demo, same place. Hit SPACE to see the PlayOnce examples. Remember to clear cache or shift-refresh to see the new version. If it doesn't have hamsters, you have the old version in your cache.

Code should be pretty self-explanatory.

I'm pondering integrating with tweening next, and also supporting automatic scaling (size pulses, etc). But it'll start to conflict with people's mouse click detection stuff, etc, or start to throw off tendrils, so... maybe not.


Raph(Posted 2014) [#4]
Version 3 supports arrays of images. This makes it a lot easier to use with atlases.

As before, not everything has been tested a lot, but the core functionality seems to work. Let me know if there's issues.

The demo bot at the bottom is using an array rather than an animstrip.

Code updated in original post. Demo link remains the same.