visual.dynamic.described
Class TweeningSprite

java.lang.Object
  extended by visual.dynamic.described.AbstractSprite
      extended by visual.dynamic.described.TweeningSprite
All Implemented Interfaces:
MetronomeListener, Sprite, SimpleContent, TransformableContent
Direct Known Subclasses:
DescribedSprite, SampledSprite

public abstract class TweeningSprite
extends AbstractSprite

A TweeningSprite is a Sprite that contains "key times" and the ability to generate "in between times"

See Also:
"The Design and Implementation of Multimedia Software © 2011"

Field Summary
protected  java.util.Vector<java.lang.Integer> keyTimes
           
protected  java.util.Vector<java.awt.geom.Point2D> locations
           
static int REMAIN
           
static int REMOVE
           
protected  java.util.Vector<java.lang.Double> rotations
           
protected  java.util.Vector<java.lang.Double> scalings
           
 
Fields inherited from class visual.dynamic.described.AbstractSprite
angle, rotationPoint, rotationX, rotationY, scaleX, scaleY, visible, x, y
 
Constructor Summary
TweeningSprite()
          Default Constructor
 
Method Summary
protected  int addKeyTime(int keyTime, java.awt.geom.Point2D location, java.lang.Double rotation, java.lang.Double scaling)
          Add a key time
protected  double getInterpolationFraction()
          Get the interpolation fraction
protected  int getKeyTimeIndex()
          Get the active key time index
protected  int getNextKeyTimeIndex()
          Get the next key time index
 void handleTick(int time)
          Handle a tick event (generated by the Stage)
protected  void initialize()
          Initialize state variables
protected  void reinitialize()
          Re-initialize state variables
 void setEndState(int endState)
          Set the "end state" for this Sprite
protected  void tweenLocation(int currentIndex, int nextIndex, double frac)
          Determine the current 'tweened location
protected  void tweenRotation(int currentIndex, int nextIndex, double frac)
          Determine the current 'tweened rotation
protected  void tweenScaling(int currentIndex, int nextIndex, double frac)
          Determine the current 'tweened scaling
 
Methods inherited from class visual.dynamic.described.AbstractSprite
getBounds2D, getBounds2D, getContent, intersects, render, setLocation, setRotation, setRotation, setScale, setScale, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyTimes

protected java.util.Vector<java.lang.Integer> keyTimes

locations

protected java.util.Vector<java.awt.geom.Point2D> locations

rotations

protected java.util.Vector<java.lang.Double> rotations

scalings

protected java.util.Vector<java.lang.Double> scalings

REMAIN

public static final int REMAIN
See Also:
Constant Field Values

REMOVE

public static final int REMOVE
See Also:
Constant Field Values
Constructor Detail

TweeningSprite

public TweeningSprite()
Default Constructor

Method Detail

addKeyTime

protected int addKeyTime(int keyTime,
                         java.awt.geom.Point2D location,
                         java.lang.Double rotation,
                         java.lang.Double scaling)
Add a key time

Parameters:
keyTime - The time
location - The location of the sprite at this time
rotation - The rotation of the sprite (null to align with path)
scaling - The scaling of the sprite at this time
Returns:
The index of this key time (or -1 if the key time exists)

handleTick

public void handleTick(int time)
Handle a tick event (generated by the Stage)

Specified by:
handleTick in interface MetronomeListener
Specified by:
handleTick in class AbstractSprite
Parameters:
time - The current time (in milliseconds)

getInterpolationFraction

protected double getInterpolationFraction()
Get the interpolation fraction

Returns:
The interpolation fraction (in [0, 1])

getKeyTimeIndex

protected int getKeyTimeIndex()
Get the active key time index

Returns:
The index of the "most recent" key time

getNextKeyTimeIndex

protected int getNextKeyTimeIndex()
Get the next key time index

Returns:
The index of the "next" key time

initialize

protected void initialize()
Initialize state variables


reinitialize

protected void reinitialize()
Re-initialize state variables

Overrides:
reinitialize in class AbstractSprite

setEndState

public void setEndState(int endState)
Set the "end state" for this Sprite

Parameters:
endState - Either REMOVE, REMAIN, or REPEAT

tweenLocation

protected void tweenLocation(int currentIndex,
                             int nextIndex,
                             double frac)
Determine the current 'tweened location

Parameters:
currentIndex - The index of the current key time
nextIndex - The index of the next key time
frac - The interpolation fraction

tweenRotation

protected void tweenRotation(int currentIndex,
                             int nextIndex,
                             double frac)
Determine the current 'tweened rotation

Parameters:
currentIndex - The index of the current key time
nextIndex - The index of the next key time
frac - The interpolation fraction

tweenScaling

protected void tweenScaling(int currentIndex,
                            int nextIndex,
                            double frac)
Determine the current 'tweened scaling

Parameters:
currentIndex - The index of the current key time
nextIndex - The index of the next key time
frac - The interpolation fraction


Design and Implementation of Multimedia Software, Jones and Bartlett Publishers