Swift Sprite System for BlitzMax now available!

BlitzMax Forums/BlitzMax Programming/Swift Sprite System for BlitzMax now available!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Absolutely it can do that.

Function Animating%(ThisSprite:Sprite, Transform%=ANIM_ALL)

There's a bunch of different animation types:

	Const ANIM_ALL%	  	= 0
	Const ANIM_POSITION% 	= 1
	Const ANIM_POSITIONX% 	= 2
	Const ANIM_POSITIONY% 	= 3
	Const ANIM_ROTATION% 	= 4
	Const ANIM_SCALE%     	= 5
	Const ANIM_SCALEX%    	= 6
	Const ANIM_SCALEY%    	= 7
	Const ANIM_COLOR%     	= 8
	Const ANIM_COLORR% 	= 9
	Const ANIM_COLORG%    	= 10
	Const ANIM_COLORB%    	= 11
	Const ANIM_ALPHA%  	= 12
	Const ANIM_FRAME%     	= 13


And you can check if any animations of a particular type are playing and/or in queue for a particular sprite.


Let's say you wanted a sprite to repeat a one second animation of frames 0 thru 9 three times.

Here is the animation function you would use:

Function Frame(ThisSprite:Sprite, StartFrame#, EndFrame#, Time%, Flags%=0, TriggerDelay%=0, FreeSprite%=False, StartAge%=0, NewImage:TImage=Null)


And here is how you would call it:

For Loop = 0 to 2
Animate.Frame(SpriteName, 0, 9, 1000, MODE_LOOP, 1000*Loop)
Next

Or, simply:

Animate.Frame(SpriteName, 0, 9, 1000, MODE_LOOP)
Animate.Frame(SpriteName, 0, 9, 1000, MODE_LOOP, 1000)
Animate.Frame(SpriteName, 0, 9, 1000, MODE_LOOP, 2000)


That will make three frame animations play. One starts immediately, the others go in a queue. The second one starts after 1 second regardless of whether the first is finished, and the third one starts at 2 seconds regardless of whether the second is finished. When one triggers, it overrides any older ones basically. But in this case the trigger times are right when the previous ones end, so you don't have to worry about that.


Now if you do this:

If Animating(SpriteName, ANIM_FRAME)

Animating will return true as long as there is a frame animation animating, or sitting in the queue on a delay timer waiting to begin.

And if you do this:

If Animating(SpriteName, ANIM_ALL)

Or this:

If Animating(SpriteName)

Then animating will return true so long as there is ANY kind of animation playing. So if you know the only kind of animation you're playing for a particular sprite is it's frame animation, then you could just do If Animating(SpriteName).

But you have the flexibility for example to make a sprite pulsate in brightness in a loop forever, but still check to see if it's frame or position animation is finished, and if that's done you can then halt the pulsating animation. Or you can simply use the ability to have the sprite automatically delete itself when the frame animation completed, and then your sprite will dissapear when it has done its job.

Ie, a score floating up might play a continuous frame animation of sparkling text. It floats up due to a Y axis animation. Meanwhile, an X axis animation with MODE_SINE and MODE_LOOP set makes it move back and forth in a sine wave forever, while an alpha animation is also playing to make it fade out. Then the position animation which is set to delete the sprite when it completes, finishes, and deletes the sprite, stopping the animations for you.

And how would you set all that up? Load an anim image, and make four animation function calls, and call the functions to update animation and draw sprites as usual.