fang2.core
Class TransformerAdapter

java.lang.Object
  extended by fang2.core.TransformerAdapter
All Implemented Interfaces:
Transformer
Direct Known Subclasses:
AccelerationTransformer, HitSpriteTransformer, KeyboardTransformer, MouseClickTransformer, MouseMovementTransformer, ShooterTransformer, SpinTransformer, TimeLimitedTransformer, VelocityTransformer, WrapTransformer

public class TransformerAdapter
extends Object
implements Transformer

The base class for all next generation transformers. Transformers are "animators" which can be attached to a sprite. While updating state during each video game loop, FANG calls advance(double) for every TransformerAdapter-derived class in the system. The transformer also gets a chance, during each frame of the game, to modify the Sprite with which it is associated. The updateSprite(Sprite) method is called each frame.

By default, updateSprite(Sprite) updates the location, rotation, and scale of the given sprite.

Note: All values (deltaLocation, deltaRotation, deltaScale) are relative by default. It is possible to override the update methods to change that and some TransformerAdapter do ((@see WrapTransformerNG} for example).


Constructor Summary
TransformerAdapter()
          Construct a new TransformerAdapter with identity settings.
TransformerAdapter(Location2D deltaLocation, double deltaRotation, double deltaScale)
          Construct a new TransformerAdapter with the given values for the instantaneous delta values.
 
Method Summary
 void advance(double dT)
          Advance the internal values of this TransformerAdapter by the given time step.
 Location2D getLocation()
          Get the amount of location this TransformerAdapter is applying at the current time (instantaneous velocity).
 double getRotation()
          Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)
 double getRotationDegrees()
          Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)
 double getRotationRadians()
          Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)
 double getRotationRevolutions()
          Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)
 double getScale()
          Get the percentage scale change this TransformerAdapter is applying at the current time
 void nonMaskableAdvance(double dT)
          Called before advance on each frame.
 void setLocation(Location2D location)
          Set the delta location (instantaneous velocity) of the TransformerAdapter
 void setLocation(Vector2D location)
          Set the delta location (instantaneous velocity) of the TransformerAdapter
 void setRotation(double radians)
          Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter
 void setRotationDegrees(double degrees)
          Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter
 void setRotationRadians(double radians)
          Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter
 void setRotationRevolutions(double revolutions)
          Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter
 void updateSprite(Sprite sprite)
          Apply the delta values to the associated values in the Sprite; this is a helper method which should be called during advance to make sure the Sprite reflects the values intended by the TransformerAdapter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformerAdapter

public TransformerAdapter()
Construct a new TransformerAdapter with identity settings.


TransformerAdapter

public TransformerAdapter(Location2D deltaLocation,
                          double deltaRotation,
                          double deltaScale)
Construct a new TransformerAdapter with the given values for the instantaneous delta values.

Parameters:
deltaLocation - change in location in screens/second
deltaRotation - change in rotation in radians/second
deltaScale - change in scale in %/second (1.00 is identity).
Method Detail

advance

public void advance(double dT)
Advance the internal values of this TransformerAdapter by the given time step. The result should be that the various attributes of this transformer are set to the delta value for the current time step.

Specified by:
advance in interface Transformer
Parameters:
dT - elapsed time since the last call to advance

getLocation

public Location2D getLocation()
Get the amount of location this TransformerAdapter is applying at the current time (instantaneous velocity).

Returns:
the delta of the location in screens

getRotation

public double getRotation()
Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)

Returns:
the delta of the rotation in radians

getRotationDegrees

public final double getRotationDegrees()
Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)

Returns:
the delta of the rotation in degrees

getRotationRadians

public final double getRotationRadians()
Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)

Returns:
the delta of the rotation in radians

getRotationRevolutions

public final double getRotationRevolutions()
Get the amount of rotation this TransformerAdapter is applying at the current time (instantaneous angular velocity)

Returns:
the delta of the rotation in revolutions

getScale

public double getScale()
Get the percentage scale change this TransformerAdapter is applying at the current time

Returns:
the delta of the scale as a fraction: 1.00 is identity

nonMaskableAdvance

public void nonMaskableAdvance(double dT)
Called before advance on each frame. Any composite/chained TransformerAdapter are required to call this on any wrapped transformers every frame.

Specified by:
nonMaskableAdvance in interface Transformer
Parameters:
dT - time since last advance in seconds.

setLocation

public void setLocation(Location2D location)
Set the delta location (instantaneous velocity) of the TransformerAdapter

Parameters:
location - the value to set

setLocation

public void setLocation(Vector2D location)
Set the delta location (instantaneous velocity) of the TransformerAdapter

Parameters:
location - the value to set

setRotation

public void setRotation(double radians)
Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter

Parameters:
radians - rotation in radians

setRotationDegrees

public final void setRotationDegrees(double degrees)
Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter

Parameters:
degrees - rotation in degrees

setRotationRadians

public final void setRotationRadians(double radians)
Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter

Parameters:
radians - rotation in radians

setRotationRevolutions

public final void setRotationRevolutions(double revolutions)
Set the delta rotation (instantaneous angular velocity) of this TransformerAdapter

Parameters:
revolutions - rotation in revolutions

updateSprite

public void updateSprite(Sprite sprite)
Apply the delta values to the associated values in the Sprite; this is a helper method which should be called during advance to make sure the Sprite reflects the values intended by the TransformerAdapter.

Specified by:
updateSprite in interface Transformer
Parameters:
sprite - the sprite to update: updated in place!