libgdx API

com.badlogic.gdx.scenes.scene2d
Class Actor

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
Direct Known Subclasses:
ComboBox.ComboList, Group, Image, Label, Widget

public abstract class Actor
extends java.lang.Object

An Actor is part of a Stage or a Group within a Stage. It has a position, a rectangular size given as width and height, a rotation angle, a scale in x and y and an origin relative to the position which is used for rotation and scaling.

The position of an Actor is coincident with its unrotated, unscaled bottom left corner.

An Actor can be a child of a Group or the Stage. The object it belongs to is called the Actor's parent. An Actor's position is always relative to the bottom left corner of its parent.

Every Actor must have a unique name within a Stage.

An Actor can receive touch events when its touchable attribute is set to true. The Stage will delegate touch events to an Actor in this case, calling its touchDown(float, float, int), touchUp(float, float, int) and touchDragged(float, float, int) methods. The coordinates passed to an Actor will be in the Actor's coordinate system, easing the pain of intersection testing. The coordinate system has it's origin at the Actor's rotated and scaled bottom left corner, with the x-axis pointing to the right and the y-axis pointing to the left.

An Actor can be intersection tested via a call this its hit(float, float) method. The coordinates given are again in the Actor's coordinate system.

An Actor might render itself when its draw(SpriteBatch, float) method is called. The projection and transform matrices are setup so that an Actor can simply call the SpriteBatch.draw(com.badlogic.gdx.graphics.Texture, float, float, float, float, float, float, float, float, float, int, int, int, int, boolean, boolean) method to render himself. Using a Sprite instance is also an option. An Actor might decide to not render itself at all or chose another way to render itself. For the later it has to call SpriteBatch.end() first, setup up all render states needed to render itself, render itself and then call SpriteBatch.begin() again so that the rendering for other Actor's is undisturbed. You have to know what you do if you want to try this.

An Actor can be controlled by Actions. An Action will modify some of the attributes of an Actor such as its position or rotation. Actions can be chained and make for rather sophisticated time based behaviour.

Author:
mzechner

Field Summary
protected  PooledLinkedList<Action> actions
           
 Color color
           
 float height
           
 java.lang.String name
           
 float originX
           
 float originY
           
 Group parent
           
 float rotation
           
 float scaleX
           
 float scaleY
           
 boolean touchable
           
 boolean visible
           
 float width
           
 float x
           
 float y
           
 
Constructor Summary
Actor()
          Creates an actor without a name.
Actor(java.lang.String name)
           
 
Method Summary
 void act(float delta)
           
 void action(Action action)
          Adds an Action to the Actor.
 void clearActions()
          Clears all actions of this Actor.
abstract  void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
abstract  Actor hit(float x, float y)
           
 boolean isMarkedToRemove()
          States if this actor is to be removed by its parent.
 boolean keyDown(int keycode)
           
 boolean keyTyped(char character)
           
 boolean keyUp(int keycode)
           
 void markToRemove(boolean remove)
          Marks the Actor to be removed by its parent.
 void remove()
          Removes this actor from the Stage
 boolean scrolled(int amount)
           
 void toLocalCoordinates(Vector2 point)
          Transforms the given point in stage coordinates to the Actor's local coordinate system.
 java.lang.String toString()
           
abstract  boolean touchDown(float x, float y, int pointer)
           
abstract  void touchDragged(float x, float y, int pointer)
           
 boolean touchMoved(float x, float y)
           
abstract  void touchUp(float x, float y, int pointer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

public Group parent

name

public final java.lang.String name

touchable

public boolean touchable

visible

public boolean visible

x

public float x

y

public float y

width

public float width

height

public float height

originX

public float originX

originY

public float originY

scaleX

public float scaleX

scaleY

public float scaleY

rotation

public float rotation

color

public final Color color

actions

protected PooledLinkedList<Action> actions
Constructor Detail

Actor

public Actor()
Creates an actor without a name.


Actor

public Actor(java.lang.String name)
Method Detail

draw

public abstract void draw(SpriteBatch batch,
                          float parentAlpha)
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

public abstract boolean touchDown(float x,
                                  float y,
                                  int pointer)

touchUp

public abstract void touchUp(float x,
                             float y,
                             int pointer)

touchDragged

public abstract void touchDragged(float x,
                                  float y,
                                  int pointer)

touchMoved

public boolean touchMoved(float x,
                          float y)

scrolled

public boolean scrolled(int amount)

keyDown

public boolean keyDown(int keycode)

keyUp

public boolean keyUp(int keycode)

keyTyped

public boolean keyTyped(char character)

hit

public abstract Actor hit(float x,
                          float y)

toLocalCoordinates

public void toLocalCoordinates(Vector2 point)
Transforms the given point in stage coordinates to the Actor's local coordinate system.

Parameters:
point - the point

remove

public void remove()
Removes this actor from the Stage


act

public void act(float delta)

action

public void action(Action action)
Adds an Action to the Actor. Actions will be automatically performed in the order added to the Actor and will be removed when they are done.

Parameters:
action - the action

clearActions

public void clearActions()
Clears all actions of this Actor.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

markToRemove

public void markToRemove(boolean remove)
Marks the Actor to be removed by its parent.

The actual removal happens in the Group.act(float) method of the parent and after the parent has called act(float) on this Actor.

Parameters:
remove - whether the parent is supposed to remove this Actor

isMarkedToRemove

public boolean isMarkedToRemove()
States if this actor is to be removed by its parent.

Returns:
true when the actor is to be removed or false otherwise

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)