MCPcopy
hub / github.com/libgdx/libgdx / Action

Class Action

gdx/src/com/badlogic/gdx/scenes/scene2d/Action.java:27–114  ·  view source on GitHub ↗

Actions attach to an Actor and perform some task, often over time. @author Nathan Sweet

Source from the content-addressed store, hash-verified

25/** Actions attach to an {@link Actor} and perform some task, often over time.
26 * @author Nathan Sweet */
27abstract public class Action implements Poolable {
28 /** The actor this action is attached to, or null if it is not attached. */
29 protected Actor actor;
30
31 /** The actor this action targets, or null if a target has not been set. */
32 protected Actor target;
33
34 private @Null Pool pool;
35
36 /** Updates the action based on time. Typically this is called each frame by {@link Actor#act(float)}.
37 * @param delta Time in seconds since the last frame.
38 * @return true if the action is done. This method may continue to be called after the action is done. */
39 abstract public boolean act (float delta);
40
41 /** Sets the state of the action so it can be run again. */
42 public void restart () {
43 }
44
45 /** Sets the actor this action is attached to. This also sets the {@link #setTarget(Actor) target} actor if it is null. This
46 * method is called automatically when an action is added to an actor. This method is also called with null when an action is
47 * removed from an actor.
48 * <p>
49 * When set to null, if the action has a {@link #setPool(Pool) pool} then the action is {@link Pool#free(Object) returned} to
50 * the pool (which calls {@link #reset()}) and the pool is set to null. If the action does not have a pool, {@link #reset()} is
51 * not called.
52 * <p>
53 * This method is not typically a good place for an action subclass to query the actor's state because the action may not be
54 * executed for some time, eg it may be {@link DelayAction delayed}. The actor's state is best queried in the first call to
55 * {@link #act(float)}. For a {@link TemporalAction}, use TemporalAction#begin(). */
56 public void setActor (Actor actor) {
57 this.actor = actor;
58 if (target == null) setTarget(actor);
59 if (actor == null) {
60 if (pool != null) {
61 pool.free(this);
62 pool = null;
63 }
64 }
65 }
66
67 /** @return null if the action is not attached to an actor. */
68 public Actor getActor () {
69 return actor;
70 }
71
72 /** Sets the actor this action will manipulate. If no target actor is set, {@link #setActor(Actor)} will set the target actor
73 * when the action is added to an actor. */
74 public void setTarget (Actor target) {
75 this.target = target;
76 }
77
78 /** @return null if the action has no target. */
79 public Actor getTarget () {
80 return target;
81 }
82
83 /** Resets the optional state of this action to as if it were newly created, allowing the action to be pooled and reused. State
84 * required to be set for every usage of this action or computed during the action does not need to be reset.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected