java.lang.Objectobjectdraw.ObjectDrawObject
objectdraw.ObjectDrawShape
objectdraw.Animation
public class Animation
Animation
is similar to VisibleImage
, but rather
than simply displaying an unchanging image, it displays an animation. After
playing through the animation, which typically takes only a few seconds, it
automatically removes itself from the canvas.
Displaying an animation is a simple as creating an Animation
object,
then telling it to start
. WHen creating the object, you can choose
one of the constants in this class to specify the type of animation, and you
can also specify an object to center the animation around. So, for example, if
player
is a VisibleImage
representing the player,
this code would display a shower of gold sparks cascading down in front of him:
new Animation(Animation.SPARKS, player).start();
It is also possible to have the animation display text labels that appear over
an object and move upwards and fade out as the animation runs. These labels
should be set before starting the animation. So, for example, this code would
make "Heal!" appear over the player as the "sparks" animation is running:
Animation animation = new Animation(Animation.SPARKS, player);
animation.label(player, "Heal!");
animation.start();
You can add as many labels as you wish to an animation in this same way.
Currently, Animation
only contains animation types I produced while
designing an RPG
project for an introductory Java course. If you have ideas for animation you
would like to see added, send a detailed description to my email address below.
Field Summary | |
---|---|
static objectdraw.Animation.AnimationType |
BURST
Animation type that shows green particles collecting around the center of the target and then bursting outward. |
static objectdraw.Animation.AnimationType |
DUSTY
Animation type that outlines the target in dark clouds of dust |
static objectdraw.Animation.AnimationType |
FROSTY
Animation type that covers the target in white layers of frost. |
static objectdraw.Animation.AnimationType |
GLOW
Animation type that halos the target in green spots, which then shoot off upward. |
static objectdraw.Animation.AnimationType |
GOLD_SHOWER
Animation type that shows a shower of golden sparks falling in front of the target. |
static objectdraw.Animation.AnimationType |
ICE_STORM
Animation type that shows large hailstones falling around its target. |
static objectdraw.Animation.AnimationType |
LIGHTNING
Animation type that shows purple lightning striking its target, followed by a white explosion. |
static objectdraw.Animation.AnimationType |
METEOR
Animation type that shows a single meteor moving from one object to strike another. |
static objectdraw.Animation.AnimationType |
METEORS
Animation type that surrounds the player with a cloud of orbiting meteors, which can be fired one by one at other targets. |
static objectdraw.Animation.AnimationType |
SHIELD
Animation type that shows a rotating sphere of green particles forming around its target. |
static objectdraw.Animation.AnimationType |
SLASH_LEFT
Animation type that shows a sword slash, moving from right to left, which leaves behind it a trail of blood that then drips down to the floor. |
static objectdraw.Animation.AnimationType |
SLASH_RIGHT
Animation type that shows a sword slash, moving from left to right, which leaves behind it a trail of blood that then drips down to the floor. |
static objectdraw.Animation.AnimationType |
SMOKE_BOMB
Animation type that shows a cloud of smoke erupting around its target. |
static objectdraw.Animation.AnimationType |
SPARKLY
Animation type that outlines the target with bright yellow sparks. |
static objectdraw.Animation.AnimationType |
SPARKS
Animation type that shows sparks rising up from the base of the target, as if it had stepped on hot coals. |
static objectdraw.Animation.AnimationType |
SPLIT
Animation type that shows a vertical line of blue arcs forming at the middle of the target and then splitting out to the two sides. |
static objectdraw.Animation.AnimationType |
SWARM
Animation type that shows an angry swarm of black particles gathering on its target. |
static objectdraw.Animation.AnimationType |
SWIRL
Animation type that shows a swirl of pink particles wrapping upwards around its target. |
static objectdraw.Animation.AnimationType |
TREASURE
Animation type that shows gold glittering in a open treasure chest, then gradually fading away. |
Constructor Summary | |
---|---|
Animation(objectdraw.Animation.AnimationType type,
DrawableInterface object)
Create an animation. |
Method Summary | |
---|---|
void |
addSpecialRegion(DrawableInterface object)
Mark the region enclosed by the given object to have some special behavior. |
void |
addToCanvas(DrawingCanvas c)
Place this object on the specified canvas. |
void |
cancel()
Cancel this animation. |
static void |
cancelAll()
Cancel every animation that is currently running. |
boolean |
contains(Location point)
Return true if the given location is inside this object, false
otherwise. |
Animation |
fireOne(DrawableInterface object)
Split off another animation targeting the given object. |
DrawingCanvas |
getCanvas()
Return the canvas that this object is on. |
Color |
getColor()
Return the color that this animation's labels are drawn with. |
int |
getCount()
Get this animation's count. |
double |
getDoubleX()
Get this object's x coordinate, in double precision. |
double |
getDoubleY()
Get this object's y coordinate, in double precision. |
Location |
getLocation()
Get this object's location. |
int |
getX()
Get this object's x coordinate. |
int |
getY()
Get this object's y coordinate. |
void |
hide()
Make this object invisible. |
boolean |
isHidden()
Return true if this object has been rendered invisible with a call to its
hide() method, false if it is still being drawn. |
void |
label(DrawableInterface object,
String label)
Produce a label that will appear in front of the given object, move upwards, and then fade out. |
void |
label(DrawableInterface object,
String label,
int dt)
Produce a label that will appear in front of the given object, move upwards, and then fade out. |
void |
move(double dx,
double dy)
Shift (translate) this object left or right by an amount dx , and up or
down by an amount dy . |
void |
moveTo(double x,
double y)
Move the center of this animation to the given (code>x, y ). |
void |
moveTo(Location point)
Move the center of this animation to the given location. |
void |
removeFromCanvas()
Remove this object from its canvas. |
void |
sendBackward()
Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it. |
void |
sendForward()
Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it. |
void |
sendToBack()
Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects. |
void |
sendToFront()
Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects. |
void |
setAttached(boolean attached)
Set whether this animation moves along with the object it decorates. |
static void |
setAttachedByDefault(boolean attached)
Set whether animations are, by default, attached to the object they decorate. |
void |
setColor(Color c)
Change the color that this animation's labels are drawn with. |
void |
setCount(int n)
Set this animation's count. |
static void |
setDefaultLabelColor(Color color)
Set the default color for animation labels to appear in. |
void |
show()
Make an object visible again after it had been hidden. |
void |
start()
Start (or restart) this animation. |
String |
toString()
Return a string describing how this object might be constructed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final objectdraw.Animation.AnimationType BURST
public static final objectdraw.Animation.AnimationType DUSTY
public static final objectdraw.Animation.AnimationType FROSTY
public static final objectdraw.Animation.AnimationType GLOW
public static final objectdraw.Animation.AnimationType GOLD_SHOWER
public static final objectdraw.Animation.AnimationType ICE_STORM
addSpecialRegion()
for each object
within whose bounds steam ought to be produced.
public static final objectdraw.Animation.AnimationType LIGHTNING
public static final objectdraw.Animation.AnimationType METEOR
Asteroid
; the destination object should be set with
addSpecialRegion(). This is also the animation type used for the meteors
fired by a METEORS
animation.
public static final objectdraw.Animation.AnimationType METEORS
setCount()
at any time before you start()
the animation.
Calling fireOne()
on an animation of this type will separate
out a single meteor into a new animation, which you can then start
as you would any other animation. This will also decrease the count by one.
So, you can tell when all the meteors have been fired, because
getCount()
will return 0.
public static final objectdraw.Animation.AnimationType SHIELD
public static final objectdraw.Animation.AnimationType SLASH_LEFT
public static final objectdraw.Animation.AnimationType SLASH_RIGHT
public static final objectdraw.Animation.AnimationType SMOKE_BOMB
public static final objectdraw.Animation.AnimationType SPARKLY
public static final objectdraw.Animation.AnimationType SPARKS
public static final objectdraw.Animation.AnimationType SPLIT
public static final objectdraw.Animation.AnimationType SWARM
public static final objectdraw.Animation.AnimationType SWIRL
public static final objectdraw.Animation.AnimationType TREASURE
Constructor Detail |
---|
public Animation(objectdraw.Animation.AnimationType type, DrawableInterface object)
type
- Type of animation. This will be one of the constants, like
Animation.SPARKS
, that are defined in this class.object
- Target of the animation. The animation will be centered
around this object.Method Detail |
---|
public void addSpecialRegion(DrawableInterface object)
object
- Objects whose bounding rectangle will be marked.public void addToCanvas(DrawingCanvas c)
null
the object is simply removed from its current canvas.
addToCanvas
in interface DrawableInterface
addToCanvas
in class objectdraw.ObjectDrawShape
c
- DrawingCanvas
to place this object onpublic void cancel()
public static void cancelAll()
public boolean contains(Location point)
true
if the given location is inside this object, false
otherwise. Because Line
s and FramedArc
s have no "inside", a
point is considered to be contained in one of them as long as it is within a few pixels
of the line.
point
- Location
to test
public Animation fireOne(DrawableInterface object)
METEORS
, that have several pieces
that can be targeted separately.
start()
'ed
just as any other newly created animation would. It can have labels or
special regions added to it first, like any other animation.
count
of this animation by one, and
if the count gets to zero, the animation is stopped and removed from
the canvas.
object
- Target of the new animation
public DrawingCanvas getCanvas()
null
.
getCanvas
in interface DrawableInterface
getCanvas
in class objectdraw.ObjectDrawShape
DrawingCanvas
that this object is on.public Color getColor()
getColor
in interface DrawableInterface
getColor
in class objectdraw.ObjectDrawShape
Color
that this animation's labels are drawn withpublic int getCount()
METEORS
that consist of several discreet
pieces. The count will be 1 unless you set it to something else.
public double getDoubleX()
public double getDoubleY()
public Location getLocation()
Location
object
will have the same effect as moving the object. So, the following two lines
of code are equivalent:
object.move(10, 20);
object.getLocation().translate(10, 20);
Location
offset by some
amount from the Location
of this object, without actually
moving this object, use the offset()
method in Location
,
which creates a new Location
.
Location
of this object.public int getX()
public int getY()
public void hide()
hide
in interface DrawableInterface
hide
in class objectdraw.ObjectDrawShape
public boolean isHidden()
true
if this object has been rendered invisible with a call to its
hide()
method, false
if it is still being drawn.
isHidden
in interface DrawableInterface
isHidden
in class objectdraw.ObjectDrawShape
public void label(DrawableInterface object, String label)
object
- Object to labellabel
- Text to displaypublic void label(DrawableInterface object, String label, int dt)
object
- Object to labellabel
- Text to displaydt
- Number of frames to wait, before the start of the animation,
before displaying the label.public void move(double dx, double dy)
dx
, and up or
down by an amount dy
. A negative dx
indicates a shift to the
left; a negative dy
indicates a shift up. If this animation is
attached to its target, the target will move with it.
move
in interface DrawableInterface
move
in class objectdraw.ObjectDrawShape
dx
- amount of x translationdy
- amount of y translationsetAttached(boolean)
public void moveTo(double x, double y)
y
).
If this animation is attached to its target, the target will move with it.
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
x
- x coordinate to move toy
- y coordinate to move tosetAttached(boolean)
public void moveTo(Location point)
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
point
- Location
to move tosetAttached(boolean)
public void removeFromCanvas()
removeFromCanvas
in interface DrawableInterface
removeFromCanvas
in class objectdraw.ObjectDrawShape
public void sendBackward()
sendBackward
in interface DrawableInterface
sendBackward
in class objectdraw.ObjectDrawShape
public void sendForward()
sendForward
in interface DrawableInterface
sendForward
in class objectdraw.ObjectDrawShape
public void sendToBack()
sendToBack
in interface DrawableInterface
sendToBack
in class objectdraw.ObjectDrawShape
public void sendToFront()
sendToFront
in interface DrawableInterface
sendToFront
in class objectdraw.ObjectDrawShape
public void setAttached(boolean attached)
attached
- public static void setAttachedByDefault(boolean attached)
attached
- Whether animations are attached to their target by defaultpublic void setColor(Color c)
setColor
in interface DrawableInterface
setColor
in class objectdraw.ObjectDrawShape
c
- new Color
for this animation's labelspublic void setCount(int n)
METEORS
that consist of several discreet
pieces. The count will be 1 unless you set it to something else. This
method must be called before start()
to have the proper effect.
The count is automatically reduced by fireOne()
, and the
animation is automatically removed from the canvas when the count gets
to zero.
n
- The number of pieces in this animation.public static void setDefaultLabelColor(Color color)
color
- Default color for labelspublic void show()
show
in interface DrawableInterface
show
in class objectdraw.ObjectDrawShape
public void start()
setCount(int)
,
label(DrawableInterface, String)
,
addSpecialRegion(DrawableInterface)
public String toString()
toString
in class objectdraw.ObjectDrawObject