vitro
Class Tweener

java.lang.Object
  extended by vitro.Tweener

public class Tweener
extends Object

A utility class for producing 2D eased animation "tweens" or interpolation. This default implementation provides a sigmoid (ease-in, ease-out) response curve.


Constructor Summary
Tweener(int x1, double length, Tweener next)
          Produce a chained 1D tween.
Tweener(int x1, int x2, double length)
          Produce a 1D tween.
Tweener(int x1, int y1, double length, Tweener next)
          Produce a chained 2D tween.
Tweener(int x1, int y1, int x2, int y2, double length)
          Produce a 1D tween.
Tweener(Point start, double length, Tweener next)
          Produce a chained 2D tween.
Tweener(Point start, Point end, double length)
          Produce a 2D tween.
 
Method Summary
 boolean done()
          Check the status of this tween of chain of tweens.
 Point position()
          A Point representing the current tweened position.
 void reset()
          Reset this Tweener and any later chained Tweener to the initial start point of the animation.
 void tick(double time)
          Advance the timer for this tween or chain of tweens.
protected  double tween(double a, double b, double t)
          The actual interpolation function.
 int x()
          Obtain the tweened x-coordinate in a 2D tween or the only tweened x-coordinate in a 1D tween, in pixels.
 double xd()
          A more accurate representation than x() for small tweens.
 int y()
          Obtain the tweened y-coordinate, in pixels.
 double yd()
          A more accurate representation than y() for small tweens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tweener

public Tweener(int x1,
               double length,
               Tweener next)
Produce a chained 1D tween.

Parameters:
x1 - the starting x-coordinate of the tween.
length - how long this tween will take (arbitrary units).
next - the Tweener to transition to after this Tweener completes.

Tweener

public Tweener(Point start,
               double length,
               Tweener next)
Produce a chained 2D tween.

Parameters:
start - the starting position of the tween.
length - how long this tween will take (arbitrary units).
next - the Tweener to transition to after this Tweener completes.

Tweener

public Tweener(int x1,
               int y1,
               double length,
               Tweener next)
Produce a chained 2D tween.

Parameters:
x1 - the starting x-coordinate of the tween.
y1 - the starting y-coordinate of the tween.
length - how long this tween will take (arbitrary units).
next - the Tweener to transition to after this Tweener completes.

Tweener

public Tweener(int x1,
               int x2,
               double length)
Produce a 1D tween.

Parameters:
x1 - the starting x-coordinate of the tween.
x2 - the final x-coordinate of the tween.
length - how long this tween will take (arbitrary units).

Tweener

public Tweener(Point start,
               Point end,
               double length)
Produce a 2D tween.

Parameters:
start - the starting position of the tween.
end - the final position of the tween.
length - how long this tween will take (arbitrary units).

Tweener

public Tweener(int x1,
               int y1,
               int x2,
               int y2,
               double length)
Produce a 1D tween.

Parameters:
x1 - the starting x-coordinate of the tween.
y1 - the starting y-coordinate of the tween.
x2 - the final x-coordinate of the tween.
y2 - the final y-coordinate of the tween.
length - how long this tween will take (arbitrary units).
Method Detail

tick

public void tick(double time)
Advance the timer for this tween or chain of tweens.

Parameters:
time - the change in time since the previous frame.

done

public boolean done()
Check the status of this tween of chain of tweens.

Returns:
true if all tweens are complete.

x

public int x()
Obtain the tweened x-coordinate in a 2D tween or the only tweened x-coordinate in a 1D tween, in pixels.

Returns:
the tweened x-coordinate.

y

public int y()
Obtain the tweened y-coordinate, in pixels. Always returns 0 in a 1D tween.

Returns:
the tweened y-coordinate.

xd

public double xd()
A more accurate representation than x() for small tweens.

Returns:
the tweened x-coordinate.

yd

public double yd()
A more accurate representation than y() for small tweens.

Returns:
the tweened y-coordinate.

position

public Point position()
A Point representing the current tweened position.

Returns:
the tweened Point.

reset

public void reset()
Reset this Tweener and any later chained Tweener to the initial start point of the animation.


tween

protected double tween(double a,
                       double b,
                       double t)
The actual interpolation function. By default, a sigmoid eased tween.

Parameters:
a - the start point of a 1D tween.
b - the end point of a 1D tween.
t - the tween value, on a range from 0 to 1.