org.gicentre.utils.network.traer.animation
Class Smoother2D

java.lang.Object
  extended by org.gicentre.utils.network.traer.animation.Smoother2D
All Implemented Interfaces:
Tickable

public class Smoother2D
extends java.lang.Object
implements Tickable

A 2D smoother for transitions towards a target over time at a rate determined by its smoothness. 2D smoothers are useful for 2D animation where two values must be transitioned together.

Version:
31st July 2012.
Author:
Jeffrey Traer Bernstein with Minor Modifications by Jo Wood.

Constructor Summary
Smoother2D(float smoothness)
          Creates a 2D smoother with the given smoothness.
Smoother2D(float startX, float startY, float smoothness)
          Creates a 2D smoother with the given smoothness and start values.
 
Method Summary
 float getX()
          Reports the current x value of the smoother.
 float getXTarget()
          Reports the target x value aimed at by this smoother at a rate determined by the smoothness.
 float getY()
          Reports the current y value of the smoother.
 float getYTarget()
          Reports the target y value aimed at by this smoother at a rate determined by the smoothness.
 void setSmoothness(float smoothness)
          Sets the smoothness value that determines the rate of transition towards a target.
 void setTarget(float targetX, float targetY)
          Sets the target values aimed at by the smoother.
 void setValue(float valueX, float valueY)
          Move the smoother to the given values immediately regardless of the smoothness value.
 void setX(float valueX)
          Move the smoother to the given x value immediately regardless of the smoothness value.
 void setXTarget(float targetX)
          Sets the target x value aimed at by the smoother.
 void setY(float valueY)
          Move the smoother to the given y value immediately regardless of the smoothness value.
 void setYTarget(float targetY)
          Sets the target y value aimed at by the smoother.
 void tick()
          Advances the time used by the smoother to move towards its targets.
 float x()
          Deprecated. Consider using getX() instead for standard accessor naming.
 float y()
          Deprecated. Consider using getY() instead for standard accessor naming.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Smoother2D

public Smoother2D(float smoothness)
Creates a 2D smoother with the given smoothness.

Parameters:
smoothness - The smoothness of the transition towards a target. It is scaled between 0 and 1. A value of 0 has abrupt changes, 1 is very smooth. A value of 0.9 gives nice workable smoothness for typical animations.

Smoother2D

public Smoother2D(float startX,
                  float startY,
                  float smoothness)
Creates a 2D smoother with the given smoothness and start values.

Parameters:
startX - Initial x value that will move towards a target.
startY - Initial y value that will move towards a target.
smoothness - The smoothness of the transition towards a target. It is scaled between 0 and 1. A value of 0 has abrupt changes, 1 is very smooth. A value of 0.9 gives nice workable smoothness for typical animations.
Method Detail

setSmoothness

public final void setSmoothness(float smoothness)
Sets the smoothness value that determines the rate of transition towards a target.

Specified by:
setSmoothness in interface Tickable
Parameters:
smoothness - The smoothness of the transition towards a target. It is scaled between 0 and 1. A value of 0 has abrupt changes, 1 is very smooth. A value of 0.9 gives nice workable smoothness for typical animations.

tick

public final void tick()
Advances the time used by the smoother to move towards its targets.

Specified by:
tick in interface Tickable

setValue

public final void setValue(float valueX,
                           float valueY)
Move the smoother to the given values immediately regardless of the smoothness value.

Parameters:
valueX - New x target value to jump to.
valueY - New y target value to jump to.

setX

public final void setX(float valueX)
Move the smoother to the given x value immediately regardless of the smoothness value.

Parameters:
valueX - New x target value to jump to.

setY

public final void setY(float valueY)
Move the smoother to the given y value immediately regardless of the smoothness value.

Parameters:
valueY - New y target value to jump to.

setTarget

public final void setTarget(float targetX,
                            float targetY)
Sets the target values aimed at by the smoother.

Parameters:
targetX - X target value aimed at by the smoother.
targetY - Y target value aimed at by the smoother.

setXTarget

public final void setXTarget(float targetX)
Sets the target x value aimed at by the smoother.

Parameters:
targetX - X target value aimed at by the smoother.

setYTarget

public final void setYTarget(float targetY)
Sets the target y value aimed at by the smoother.

Parameters:
targetY - Y target value aimed at by the smoother.

getXTarget

public final float getXTarget()
Reports the target x value aimed at by this smoother at a rate determined by the smoothness.

Returns:
x target of the smoother.

getYTarget

public final float getYTarget()
Reports the target y value aimed at by this smoother at a rate determined by the smoothness.

Returns:
y target of the smoother.

x

public final float x()
Deprecated. Consider using getX() instead for standard accessor naming.

Reports the current x value of the smoother. This will be somewhere between the source and target x values depending on the smoothness and number of times tick() has been called.

Returns:
Current x value of the smoother.

getX

public final float getX()
Reports the current x value of the smoother. This will be somewhere between the source and target x values depending on the smoothness and number of times tick() has been called.

Returns:
Current x value of the smoother.

y

public final float y()
Deprecated. Consider using getY() instead for standard accessor naming.

Reports the current y value of the smoother. This will be somewhere between the source and target y values depending on the smoothness and number of times tick() has been called.

Returns:
Current y value of the smoother.

getY

public final float getY()
Reports the current y value of the smoother. This will be somewhere between the source and target y values depending on the smoothness and number of times tick() has been called.

Returns:
Current y value of the smoother.


giCentre Utilities V.3.3, API documentation generated 6th April, 2013