com.threerings.media.animation
Class SparkAnimation

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.animation.Animation
          extended by com.threerings.media.animation.SparkAnimation
All Implemented Interfaces:
Shape

public class SparkAnimation
extends Animation

Displays a set of spark images originating from a specified position and flying outward in random directions, fading out as they go, for a specified period of time.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.animation.Animation
Animation.AnimCompletedOp, Animation.AnimStartedOp
 
Field Summary
protected  float _alpha
          The percent alpha with which to render the images.
protected  AlphaComposite _comp
          The alpha composite with which to render the images.
protected  long _delay
          The duration of the spark animation in milliseconds.
protected  boolean _fade
          Whether or not we should fade the sparks out.
protected  int _icount
          The number of images we're animating.
protected  Mirage[] _images
          The spark images we're animating.
protected  int[] _ox
          The starting 'jog' positions for each spark.
protected  int[] _oy
          The starting 'jog' positions for each spark.
protected  long _start
          The starting animation time.
protected  float[] _sxvel
          The starting x-axis velocity of each chunk.
protected  float[] _syvel
          The starting y-axis velocity of each chunk.
protected  float _xacc
          The x axis acceleration in pixels per millisecond.
protected  int[] _xpos
          The current positions of each spark.
protected  float _yacc
          The y axis acceleration in pixels per millisecond.
protected  int[] _ypos
          The current positions of each spark.
 
Fields inherited from class com.threerings.media.animation.Animation
_finished
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Constructor Summary
SparkAnimation(Rectangle bounds, int x, int y, int xjog, int yjog, float minxvel, float minyvel, float maxxvel, float maxyvel, float xacc, float yacc, Mirage[] images, long delay, boolean fade)
          Constructs a spark animation with the supplied parameters.
 
Method Summary
 void fastForward(long timeDelta)
          Called when the appropriate media manager has been paused for some length of time and is then unpaused.
 void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
protected  int randomDirection()
          Returns at random -1 for negative direction or +1 for positive.
 void tick(long timestamp)
          Called periodically by this media's manager to give it a chance to do its thing.
protected  void toString(StringBuilder buf)
          This should be overridden by derived classes (which should be sure to call super.toString()) to append the derived class specific information to the string buffer.
protected  void willStart(long stamp)
          Prior to the first call to AbstractMedia.tick(long) on an abstract media, this method is called by the AbstractMediaManager.
 
Methods inherited from class com.threerings.media.animation.Animation
addAnimationObserver, didFinish, isFinished, removeAnimationObserver, reset, setLocation, willFinish
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, shutdown, toString, viewLocationDidChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_images

protected Mirage[] _images
The spark images we're animating.


_icount

protected int _icount
The number of images we're animating.


_xacc

protected float _xacc
The x axis acceleration in pixels per millisecond.


_yacc

protected float _yacc
The y axis acceleration in pixels per millisecond.


_sxvel

protected float[] _sxvel
The starting x-axis velocity of each chunk.


_syvel

protected float[] _syvel
The starting y-axis velocity of each chunk.


_ox

protected int[] _ox
The starting 'jog' positions for each spark.


_oy

protected int[] _oy
The starting 'jog' positions for each spark.


_xpos

protected int[] _xpos
The current positions of each spark.


_ypos

protected int[] _ypos
The current positions of each spark.


_start

protected long _start
The starting animation time.


_fade

protected boolean _fade
Whether or not we should fade the sparks out.


_alpha

protected float _alpha
The percent alpha with which to render the images.


_comp

protected AlphaComposite _comp
The alpha composite with which to render the images.


_delay

protected long _delay
The duration of the spark animation in milliseconds.

Constructor Detail

SparkAnimation

public SparkAnimation(Rectangle bounds,
                      int x,
                      int y,
                      int xjog,
                      int yjog,
                      float minxvel,
                      float minyvel,
                      float maxxvel,
                      float maxyvel,
                      float xacc,
                      float yacc,
                      Mirage[] images,
                      long delay,
                      boolean fade)
Constructs a spark animation with the supplied parameters.

Parameters:
bounds - the bounding rectangle for the animation.
x - the starting x-position for the sparks.
y - the starting y-position for the sparks.
xjog - the maximum X distance by which to "jog" the initial spark positions, or 0 if no jogging is desired.
yjog - the maximum Y distance by which to "jog" the initial spark positions, or 0 if no jogging is desired.
minxvel - the minimum starting x-velocity of the sparks.
minyvel - the minimum starting y-velocity of the sparks.
maxxvel - the maximum x-velocity of the sparks.
maxyvel - the maximum y-velocity of the sparks.
xacc - the x axis acceleration, or 0 if none is desired.
yacc - the y axis acceleration, or 0 if none is desired.
images - the spark images to be animated.
delay - the duration of the animation in milliseconds.
fade - do the fade thing
Method Detail

randomDirection

protected int randomDirection()
Returns at random -1 for negative direction or +1 for positive.


willStart

protected void willStart(long stamp)
Description copied from class: AbstractMedia
Prior to the first call to AbstractMedia.tick(long) on an abstract media, this method is called by the AbstractMediaManager. It is called during the normal tick cycle, immediately prior to the first call to AbstractMedia.tick(long).

Note: It is imperative that super.willStart() is called by any entity that overrides this method because the AbstractMediaManager depends on the setting of the AbstractMedia._firstTick value to know whether or not to call this method.

Overrides:
willStart in class Animation

fastForward

public void fastForward(long timeDelta)
Description copied from class: AbstractMedia
Called when the appropriate media manager has been paused for some length of time and is then unpaused. Media should adjust any time stamps that are maintained internally forward by the delta so that time maintains the illusion of flowing smoothly forward.

Overrides:
fastForward in class AbstractMedia

tick

public void tick(long timestamp)
Description copied from class: AbstractMedia
Called periodically by this media's manager to give it a chance to do its thing.

Specified by:
tick in class AbstractMedia
Parameters:
timestamp - a time stamp associated with this tick. Note: this is not obtained from a call to System.currentTimeMillis() and cannot be compared to timestamps obtained there from.

paint

public void paint(Graphics2D gfx)
Description copied from class: AbstractMedia
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.

Specified by:
paint in class AbstractMedia

toString

protected void toString(StringBuilder buf)
Description copied from class: AbstractMedia
This should be overridden by derived classes (which should be sure to call super.toString()) to append the derived class specific information to the string buffer.

Overrides:
toString in class AbstractMedia