Class Action

java.lang.Object
com.prineside.tdi2.scene2d.Action
All Implemented Interfaces:
Pool.Poolable
Direct Known Subclasses:
AddAction, AddListenerAction, DelegateAction, EventAction, LayoutAction, ParallelAction, RemoveAction, RemoveActorAction, RemoveListenerAction, RunnableAction, TemporalAction, TouchableAction, VisibleAction

public abstract class Action extends Object implements Pool.Poolable
Actions attach to an Actor and perform some task, often over time.
Author:
Nathan Sweet
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    act(float delta)
    Updates the action based on time.
     
     
     
    void
    Resets the optional state of this action to as if it were newly created, allowing the action to be pooled and reused.
    void
    Sets the state of the action so it can be run again.
    void
    setActor(Actor actor)
    Sets the actor this action is attached to.
    void
    setPool(Pool pool)
    Sets the pool that the action will be returned to when removed from the actor.
    void
    setTarget(Actor target)
    Sets the actor this action will manipulate.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Action

      public Action()
  • Method Details

    • act

      public abstract boolean act(float delta)
      Updates the action based on time. Typically this is called each frame by Actor.act(float).
      Parameters:
      delta - Time in seconds since the last frame.
      Returns:
      true if the action is done. This method may continue to be called after the action is done.
    • restart

      public void restart()
      Sets the state of the action so it can be run again.
    • setActor

      public void setActor(Actor actor)
      Sets the actor this action is attached to. This also sets the target actor if it is null. This method is called automatically when an action is added to an actor. This method is also called with null when an action is removed from an actor.

      When set to null, if the action has a pool then the action is returned to the pool (which calls reset()) and the pool is set to null. If the action does not have a pool, reset() is not called.

      This method is not typically a good place for an action subclass to query the actor's state because the action may not be executed for some time, eg it may be delayed. The actor's state is best queried in the first call to act(float). For a TemporalAction, use TemporalAction#begin().

    • getActor

      public Actor getActor()
      Returns:
      null if the action is not attached to an actor.
    • setTarget

      public void setTarget(Actor target)
      Sets the actor this action will manipulate. If no target actor is set, setActor(Actor) will set the target actor when the action is added to an actor.
    • getTarget

      public Actor getTarget()
      Returns:
      null if the action has no target.
    • reset

      public void reset()
      Resets the optional state of this action to as if it were newly created, allowing the action to be pooled and reused. State required to be set for every usage of this action or computed during the action does not need to be reset.

      The default implementation calls restart().

      If a subclass has optional state, it must override this method, call super, and reset the optional state.

      Specified by:
      reset in interface Pool.Poolable
    • getPool

      @Null public Pool getPool()
    • setPool

      public void setPool(@Null Pool pool)
      Sets the pool that the action will be returned to when removed from the actor.
      Parameters:
      pool - May be null.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object