fang
Class OutlineTransformer

java.lang.Object
  extended by fang.Transformer
      extended by fang.OutlineTransformer
All Implemented Interfaces:
Tracker
Direct Known Subclasses:
OutlineTracker

public class OutlineTransformer
extends Transformer

This tracker enables a path to be created from any shape or Sprite.

Author:
Jam Jenkins

Constructor Summary
OutlineTransformer(double speed, double... vertices)
          creates the tracker given a path to move on and a speed to travel.
OutlineTransformer(Shape outline, double speed)
          creates the tracker given a Shape to move around and a speed to travel.
OutlineTransformer(Sprite outline, double speed)
          creates the tracker given a Sprite to move around and a speed to travel.
 
Method Summary
 void advance(double elapsedSeconds)
           
 void advanceDistance(double distance)
          moves along the outline a given distance.
 Location2D getCurrentPoint()
          gets the current location along the outline.
 double getPathDistance()
          gets the distance around the entire outline of the shape
 double getSpeed()
          sets the speed of the tracker
 Location2D getTranslation()
          returns (0, 0)
 boolean isLooping()
          tells whether the tracker should stop moving once it goes all the way around the shape or if it should move continuously
 boolean isMoving()
           
 void reset()
          resets the tracker to the beginning of tracing the current shape/path
 void setLooping(boolean looping)
          sets whether the tracker should stop moving once it goes all the way around the shape or if it should move continuously
 void setShape(double... vertices)
           
 void setShape(Shape shape)
          sets the shape to traverse
 void setShape(Sprite sprite)
          sets the shape to traverse
 void setSpeed(double speed)
          sets the speed of the tracker
 void skipDistance(double distance)
          skips past a part of the outline.
 
Methods inherited from class fang.Transformer
advance, advanceTime, getGame, getRotationAddition, getRotationAdditionDegrees, getRotationAdditionRadians, getRotationAdditionRevolutions, getScaleFactor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutlineTransformer

public OutlineTransformer(Sprite outline,
                          double speed)
creates the tracker given a Sprite to move around and a speed to travel. If you want to make the sprite travel along the actual Sprite instead of just in the shape of the Sprite, you also need to set the original location of the Sprite moving to the current location of the OutlineTracker using the method getCurrentPoint().

Parameters:
outline - the sprite on which to traverse the outline
speed - the portion of the screen to move per second

OutlineTransformer

public OutlineTransformer(Shape outline,
                          double speed)
creates the tracker given a Shape to move around and a speed to travel. If you want to make the sprite travel along the actual Sprite instead of just in the shape of the Sprite, you also need to set the original location of the Sprite moving to the current location of the OutlineTracker using the method getCurrentPoint().

Parameters:
outline - the shape on which to traverse the outline
speed - the portion of the screen to move per second

OutlineTransformer

public OutlineTransformer(double speed,
                          double... vertices)
creates the tracker given a path to move on and a speed to travel. If you want to make the sprite travel along the actual path instead of just in the shape of the path, you also need to set the original location of the Sprite moving to the current location of the OutlineTracker using the method getCurrentPoint().

Parameters:
speed - the portion of the screen to move per second
vertices - the location of the vertices along the path
Method Detail

getCurrentPoint

public Location2D getCurrentPoint()
gets the current location along the outline. This method is useful to call if you want the Sprite that is moving to stay on the outline of the original Shape/Sprite.

Returns:
the location along the outline

setLooping

public void setLooping(boolean looping)
sets whether the tracker should stop moving once it goes all the way around the shape or if it should move continuously

Parameters:
looping - true indicates move continuously and false means stop when the shape have bee traversed. Calling skipDistance can cause less than the entire shape to be traversed if looping is false.

isLooping

public boolean isLooping()
tells whether the tracker should stop moving once it goes all the way around the shape or if it should move continuously

Returns:
true if the tracker moves continously or false if it stops once the shape has been traversed

getPathDistance

public double getPathDistance()
gets the distance around the entire outline of the shape

Returns:
the perimeter of the shape

skipDistance

public void skipDistance(double distance)
skips past a part of the outline. If the amount skipped past moves past the end of the outline and looping is false, the tracker will continue moving around the shape again until it reaches the end. Calling this method does not move the tracker, it just changes where it starts and alters the currrentPoint.

Parameters:
distance - the amount to skip. This can be used in conjunction with getPathDistance.

advanceDistance

public void advanceDistance(double distance)
moves along the outline a given distance. Unlike shipDistance, this has the effect of moving the tracker and it changes currentPoint.

Parameters:
distance - the amount to move around the outline

setShape

public void setShape(Sprite sprite)
sets the shape to traverse

Parameters:
sprite - the sprite to trace the outline of

setShape

public void setShape(Shape shape)
sets the shape to traverse

Parameters:
shape - the shape to trace the outline of

setShape

public void setShape(double... vertices)

reset

public void reset()
resets the tracker to the beginning of tracing the current shape/path


isMoving

public boolean isMoving()

setSpeed

public void setSpeed(double speed)
sets the speed of the tracker

Parameters:
speed - the speed of the tracker in screens per second

getSpeed

public double getSpeed()
sets the speed of the tracker

Returns:
the speed of the tracker in screens per second

getTranslation

public Location2D getTranslation()
Description copied from class: Transformer
returns (0, 0)

Specified by:
getTranslation in interface Tracker
Overrides:
getTranslation in class Transformer
Returns:
the absolute location of the Sprite
See Also:
fang.core.Tracker#getTranslation()

advance

public void advance(double elapsedSeconds)
Overrides:
advance in class Transformer