Game Development Reference
In-Depth Information
The following example illustrates the typical method signatures of two actions:
moveTo (x, y);
moveTo (x, y, duration);
moveTo (x, y, duration, interpolation);
rotateTo (rotation);
rotateTo (rotation, duration);
rotateTo (rotation, duration, interpolation);
Both the moveTo() and rotateTo() actions have their action-specific parameters x ,
y , and rotation , respectively, which is the absolute minimum requirement. In this
case, both actions can also take an optional duration and interpolation parameter
if needed.
The methods of the Actions class are intended for static import. There
are mainly two reasons for this: convenience and increased readability
when chaining together multiple actions. The preceding example code
and each following code using the Actions class will assume the use of
static imports.
In Java, a static import can be used to make static methods of one class
available in the namespace of another class, thus removing the need to
use the class qualification in order to call such methods.
For more information about static imports, check out http://docs.
oracle.com/javase/1.5.0/docs/guide/language/static-
import.html .
Now, to add one or more actions to an actor, we simply need to call its addAction()
method as follows:
Actor actor = new Actor();
float x = 100.0f, y = 100.0f, rotation = 0.0f, duration = 1.0f;
actor.addAction(sequence(
moveTo(x, y),
rotateTo(rotation),
delay(duration),
parallel(
moveBy(50.0f, 0.0f, 5.0f),
rotateBy(90.0f, 5.0f, Interpolation.swingOut))));
 
Search WWH ::




Custom Search