public class Action
extends java.lang.Object
Sprite
over time.
Actions are typically created with the static methods in the
ActionFactory class, added to the target Sprite, and will then be applied
automatically. Custom Action objects may be created by using lambda
expressions that conform to the Function interface, such as:
Action teleportRight = new Action(
(target, deltaTime, totalTime) ->
{
target.moveBy(100, 0);
return true;
}
);
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
Action.Function
This interface is used internally by the Action class to encapsulate a
method that will be applied to a target Sprite.
|
Modifier and Type | Field and Description |
---|---|
(package private) Action.Function |
function
Encapsulates the method that will be applied to the Sprite this Action is attached to.
|
(package private) double |
totalTime
The total time that has elapsed since the Action has started.
|
Constructor and Description |
---|
Action()
This constructor is used by
ActionFactory methods that need to extend the Action class to store additional information or override methods, typically involving one or more additional Actions (see ActionFactory.sequence, repeat, forever). |
Action(Action.Function f)
This constructor is used by simple
ActionFactory methods or to create custom Action objects. |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
apply(Sprite target,
double deltaTime)
Increments totalTime by deltaTime and applies function.run method to target.
|
void |
reset()
Sets
totalTime to 0, effectively restarting this Action. |
double totalTime
Action.Function function
Action()
ActionFactory
methods that need to extend the Action class to store additional information or override methods, typically involving one or more additional Actions (see ActionFactory.sequence, repeat, forever).public Action(Action.Function f)
ActionFactory
methods or to create custom Action objects.f
- Function object that encapsulates the method that will be applied to the Sprite this Action is attached to.boolean apply(Sprite target, double deltaTime)
target
- Sprite to which the function.run method will be applieddeltaTime
- elapsed time (seconds) since previous iteration of game loop (typically approximately 1/60 second)public void reset()
totalTime
to 0, effectively restarting this Action.