Animation class was originally created simply to be used in a particular RPG project, but it turned out to be so much fun that I integrated it into ObjectDraw. The basic idea is that an animation "decrates" some other object, playing a brief animation centered on that object (and sometimes tracing its outline) Try clicking below to see some of the animations that exist so far:
Table of Contents
1. Creating and running animationsPlaying an animation works in two steps: first, you create the animation, telling it which object to decorate and which animation to play, and then you tell it to start:
Animation anim = new Animation(Animation.DUSTY, new FilledOval(50, 50, 100, 100, canvas));
The animation will automatically add itself to the same canvas that the object you gave it belongs to. When it is done animating, it will automatically remove itself from that canvas.
You can restart the animation at any time by calling the
start() method again. This will cancel what it is doing if it is still animating, and will send it back to the start of the animation.
Animations normally move when the decorated object is moved. If this is not the behavior you want, you can change it with the
setAttached(boolean) method. If you want all your animations to by default not be attached to the decorated object, you can use the class method
Animation.setAttachedByDefault(boolean) to change this.
2. Adding labels to the animationAn animation may also display test labels rising up from any number of objects on the canvas. This was originally meant to be used in the RPG to display the damage done by an attack, but it is possible that you can come up with other uses for it.
To add a new label to an animation, use one of these two methods:
public void label(DrawableInterface object, String label)
public void label(DrawableInterface object, String label, int dt)
dt parameter, if given, specifies how many frames after the start of the animation the label ought to first appear. This allows you to, for example, time the label to appear when a meteor hits its target, as you wee in the example above. There are thirty frames in a second.
The color of the labels is controlled by
setColor(). They are all the same color for a particular
Animation. If you want to change the default color to something other than black, you can use the class method
3. Setting special regionsSome animations react in some way to objects on the screen other than the one they were made to decorate. For example, the
METEOR animation will move toward another object and explode when it hits it. More subtly, the
ICE_STORM animation has hailstones that normally break up into pieces when they hit the ground, but it is possible to have them turn into steam instead of you want a particular object to act as if it is really hot.
You can add other objects that you want the animation to use by calling this method:
public void addSpecialRegion(DrawableInterface object)
4. Firing part of the animationThe
METEORS animation shows a cloud of meteors circling the decorated object. You can set the number of meteors with the
setCount() method, prior to starting the animation. Those meteors can be fired one by one at various targets by using the
fireOne() method, which returns a new
Animation that will animate a single meteor moving toward the target.
5. Javadoc for the The javadoc for the
Animation class is here. This is the place to look for a description of all the animation types.
If you have ideas for other animation types that you would like to see, send me by email a precise description of what the animation would look like, and I'll let you know when I've integrated it into ObjectDraw. In general, animations are "particle" based - that is, they are created by drawing lots of tiny images that move around following simple rules.