public class Actor extends Object
An actor has a list of in progress actions
that are applied to the actor (often over time). These are generally
used to change the presentation of the actor (moving it, resizing it, etc). See act(float)
, Action
and its
many subclasses.
An actor has two kinds of listeners associated with it: "capture" and regular. The listeners are notified of events the actor
or its children receive. The regular listeners are designed to allow an actor to respond to events that have been delivered.
The capture listeners are designed to allow a parent or container actor to handle events before child actors. See fire(com.badlogic.gdx.scenes.scene2d.Event)
for more details.
An InputListener
can receive all the basic input events. More complex listeners (like ClickListener
and
ActorGestureListener
) can listen for and combine primitive events and recognize complex interactions like multi-touch
or pinch.
Constructor and Description |
---|
Actor() |
Modifier and Type | Method and Description |
---|---|
void |
act(float delta)
Updates the actor based on time.
|
void |
addAction(Action action) |
boolean |
addCaptureListener(EventListener listener)
Adds a listener that is only notified during the capture phase.
|
boolean |
addListener(EventListener listener)
Add a listener to receive events that
hit this actor. |
void |
clear()
Removes all actions and listeners on this actor.
|
void |
clearActions()
Removes all actions on this actor.
|
void |
clearListeners()
Removes all listeners on this actor.
|
boolean |
clipBegin()
Calls
clipBegin(float, float, float, float) to clip this actor's bounds. |
boolean |
clipBegin(float x,
float y,
float width,
float height)
Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch.
|
void |
clipEnd()
Ends clipping begun by
clipBegin(float, float, float, float) . |
Actor |
debug()
Calls
setDebug(boolean) with true . |
void |
draw(Batch batch,
float parentAlpha)
Draws the actor.
|
void |
drawDebug(ShapeRenderer shapes)
Draws this actor's debug lines if
getDebug() is true. |
boolean |
fire(Event event)
Sets this actor as the event
target and propagates the event to this actor and ancestor
actors as necessary. |
Array<Action> |
getActions() |
Array<EventListener> |
getCaptureListeners() |
Color |
getColor()
Returns the color the actor will be tinted when drawn.
|
boolean |
getDebug() |
float |
getHeight() |
Array<EventListener> |
getListeners() |
String |
getName()
Retrieve custom actor name set with
setName(String) , used for easier identification |
float |
getOriginX() |
float |
getOriginY() |
Group |
getParent()
Returns the parent actor, or null if not in a group.
|
float |
getRight()
Returns x plus width.
|
float |
getRotation() |
float |
getScaleX() |
float |
getScaleY() |
Stage |
getStage()
Returns the stage that this actor is currently in, or null if not in a stage.
|
float |
getTop()
Returns y plus height.
|
Touchable |
getTouchable() |
Object |
getUserObject()
Returns an application specific object for convenience, or null.
|
float |
getWidth() |
float |
getX()
Returns the X position of the actor's left edge.
|
float |
getX(int alignment)
Returns the X position of the specified
alignment . |
float |
getY()
Returns the Y position of the actor's bottom edge.
|
float |
getY(int alignment)
Returns the Y position of the specified
alignment . |
int |
getZIndex()
Returns the z-index of this actor.
|
boolean |
hasParent()
Returns true if the actor's parent is not null.
|
Actor |
hit(float x,
float y,
boolean touchable)
|
boolean |
isAscendantOf(Actor actor)
Returns true if this actor is the same as or is the ascendant of the specified actor.
|
boolean |
isDescendantOf(Actor actor)
Returns true if this actor is the same as or is the descendant of the specified actor.
|
boolean |
isTouchable()
Returns true if input events are processed by this actor.
|
boolean |
isVisible() |
Vector2 |
localToAscendantCoordinates(Actor ascendant,
Vector2 localCoords)
Converts coordinates for this actor to those of a parent actor.
|
Vector2 |
localToParentCoordinates(Vector2 localCoords)
Transforms the specified point in the actor's coordinates to be in the parent's coordinates.
|
Vector2 |
localToStageCoordinates(Vector2 localCoords)
Transforms the specified point in the actor's coordinates to be in the stage's coordinates.
|
void |
moveBy(float x,
float y)
Add x and y to current position
|
boolean |
notify(Event event,
boolean capture)
Notifies this actor's listeners of the event.
|
Vector2 |
parentToLocalCoordinates(Vector2 parentCoords)
Converts the coordinates given in the parent's coordinate system to this actor's coordinate system.
|
boolean |
remove()
Removes this actor from its parent, if it has a parent.
|
void |
removeAction(Action action) |
boolean |
removeCaptureListener(EventListener listener) |
boolean |
removeListener(EventListener listener) |
void |
rotateBy(float amountInDegrees)
Adds the specified rotation to the current rotation.
|
void |
scaleBy(float scale)
Adds the specified scale to the current scale.
|
void |
scaleBy(float scaleX,
float scaleY)
Adds the specified scale to the current scale.
|
Vector2 |
screenToLocalCoordinates(Vector2 screenCoords)
Transforms the specified point in screen coordinates to the actor's local coordinate system.
|
void |
setBounds(float x,
float y,
float width,
float height)
Set bounds the x, y, width, and height.
|
void |
setColor(Color color) |
void |
setColor(float r,
float g,
float b,
float a) |
void |
setDebug(boolean enabled)
If true,
drawDebug(ShapeRenderer) will be called for this actor. |
void |
setHeight(float height) |
void |
setName(String name)
Sets a name for easier identification of the actor in application code.
|
void |
setOrigin(float originX,
float originY)
Sets the origin position which is relative to the actor's bottom left corner.
|
void |
setOrigin(int alignment)
Sets the origin position to the specified
alignment . |
void |
setOriginX(float originX) |
void |
setOriginY(float originY) |
void |
setPosition(float x,
float y)
Sets the position of the actor's bottom left corner.
|
void |
setPosition(float x,
float y,
int alignment)
Sets the position using the specified
alignment . |
void |
setRotation(float degrees) |
void |
setScale(float scaleXY)
Sets the scale for both X and Y
|
void |
setScale(float scaleX,
float scaleY)
Sets the scale X and scale Y.
|
void |
setScaleX(float scaleX) |
void |
setScaleY(float scaleY) |
void |
setSize(float width,
float height)
Sets the width and height.
|
void |
setTouchable(Touchable touchable)
Determines how touch events are distributed to this actor.
|
void |
setUserObject(Object userObject)
Sets an application specific object for convenience.
|
void |
setVisible(boolean visible)
If false, the actor will not be drawn and will not receive touch events.
|
void |
setWidth(float width) |
void |
setX(float x) |
void |
setY(float y) |
void |
setZIndex(int index)
Sets the z-index of this actor.
|
void |
sizeBy(float size)
Adds the specified size to the current size.
|
void |
sizeBy(float width,
float height)
Adds the specified size to the current size.
|
Vector2 |
stageToLocalCoordinates(Vector2 stageCoords)
Transforms the specified point in the stage's coordinates to the actor's local coordinate system.
|
void |
toBack()
Changes the z-order for this actor so it is in back of all siblings.
|
void |
toFront()
Changes the z-order for this actor so it is in front of all siblings.
|
String |
toString() |
public void draw(Batch batch, float parentAlpha)
This draw method
is convenient to draw a rotated and scaled TextureRegion. Batch.begin()
has already been called on
the batch. If Batch.end()
is called to draw without the batch then Batch.begin()
must be called before the
method returns.
The default implementation does nothing.
parentAlpha
- Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.public void act(float delta)
Stage.act(float)
.
The default implementation calls Action.act(float)
on each action and removes actions that are complete.
delta
- Time in seconds since the last frame.public boolean fire(Event event)
target
and propagates the event to this actor and ancestor
actors as necessary. If this actor is not in the stage, the stage must be set before calling this method.
Events are fired in 2 phases.
Event.getBubbles()
is true,
propagating upward to the root.stopped
at any time, it will not propagate to the next actor.cancelled
.public boolean notify(Event event, boolean capture)
listener actor
. The event target
must be set before calling this method. If this actor is not in the stage, the stage must be set before calling this method.capture
- If true, the capture listeners will be notified instead of the regular listeners.cancelled
.public Actor hit(float x, float y, boolean touchable)
touchable
and
visible
, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0
is the bottom left of the actor and width,height is the upper right).
This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.
The default implementation returns this actor if the point is within this actor's bounds.
touchable
- If true, the hit detection will respect the touchability
.Touchable
public boolean remove()
Group.removeActor(Actor)
public boolean addListener(EventListener listener)
hit
this actor. See fire(Event)
.InputListener
,
ClickListener
public boolean removeListener(EventListener listener)
public Array<EventListener> getListeners()
public boolean addCaptureListener(EventListener listener)
fire(Event)
public boolean removeCaptureListener(EventListener listener)
public Array<EventListener> getCaptureListeners()
public void addAction(Action action)
public void removeAction(Action action)
public void clearActions()
public void clearListeners()
public void clear()
public Stage getStage()
public boolean isDescendantOf(Actor actor)
public boolean isAscendantOf(Actor actor)
public boolean hasParent()
public Group getParent()
public boolean isTouchable()
public Touchable getTouchable()
public void setTouchable(Touchable touchable)
Touchable.enabled
.public boolean isVisible()
public void setVisible(boolean visible)
public Object getUserObject()
public void setUserObject(Object userObject)
public float getX()
public float getX(int alignment)
alignment
.public void setX(float x)
public float getY()
public void setY(float y)
public float getY(int alignment)
alignment
.public void setPosition(float x, float y)
public void setPosition(float x, float y, int alignment)
alignment
. Note this may set the position to non-integer coordinates.public void moveBy(float x, float y)
public float getWidth()
public void setWidth(float width)
public float getHeight()
public void setHeight(float height)
public float getTop()
public float getRight()
public void setSize(float width, float height)
public void sizeBy(float size)
public void sizeBy(float width, float height)
public void setBounds(float x, float y, float width, float height)
public float getOriginX()
public void setOriginX(float originX)
public float getOriginY()
public void setOriginY(float originY)
public void setOrigin(float originX, float originY)
public void setOrigin(int alignment)
alignment
.public float getScaleX()
public void setScaleX(float scaleX)
public float getScaleY()
public void setScaleY(float scaleY)
public void setScale(float scaleXY)
public void setScale(float scaleX, float scaleY)
public void scaleBy(float scale)
public void scaleBy(float scaleX, float scaleY)
public float getRotation()
public void setRotation(float degrees)
public void rotateBy(float amountInDegrees)
public void setColor(Color color)
public void setColor(float r, float g, float b, float a)
public Color getColor()
public String getName()
setName(String)
, used for easier identificationpublic void setName(String name)
Group.findActor(String)
public void toFront()
public void toBack()
public void setZIndex(int index)
children
, where a
lower index is below a higher index. Setting a z-index higher than the number of children will move the child to the front.
Setting a z-index less than zero is invalid.public int getZIndex()
setZIndex(int)
public boolean clipBegin()
clipBegin(float, float, float, float)
to clip this actor's bounds.public boolean clipBegin(float x, float y, float width, float height)
clipEnd()
if true is returned.ScissorStack
public void clipEnd()
clipBegin(float, float, float, float)
.public Vector2 screenToLocalCoordinates(Vector2 screenCoords)
public Vector2 stageToLocalCoordinates(Vector2 stageCoords)
public Vector2 localToStageCoordinates(Vector2 localCoords)
public Vector2 localToParentCoordinates(Vector2 localCoords)
public Vector2 localToAscendantCoordinates(Actor ascendant, Vector2 localCoords)
public Vector2 parentToLocalCoordinates(Vector2 parentCoords)
public void drawDebug(ShapeRenderer shapes)
getDebug()
is true.public void setDebug(boolean enabled)
drawDebug(ShapeRenderer)
will be called for this actor.public boolean getDebug()
public Actor debug()
setDebug(boolean)
with true
.Copyright © 2015. All rights reserved.