|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.InputAdapter
com.badlogic.gdx.scenes.scene2d.Stage
public class Stage
A Stage is a container for Actor
s and handles distributing touch events, animating Actors and asking them to render
themselves. A Stage is basically a 2D scenegraph with hierarchies of Actors.
A Stage object fills the whole screen. It has a width and height given in device independent pixels. It will create a
Camera
that maps this viewport to the given real screen resolution. If the stretched attribute is set to true then the
viewport is enforced no matter the difference in aspect ratio between the stage object and the screen dimensions. In case
stretch is disabled then the viewport is extended in the bigger screen dimensions.
Actors have a z-order which is equal to the order they were inserted into this Stage. Actors inserted later will be drawn on top of Actors added earlier. Touch events that will get distributed to later Actors first.
Actors can get focused. When your game pauses and resumes make sure to call the unfocusAll()
method so that the
focus states get reset for each pointer id. You also have to make sure that the Actors that were focused reset their state if
the depend on being focused, e.g. wait for a touch up event. An easier way to tackle this is to recreate the Stage if possible.
Field Summary | |
---|---|
protected SpriteBatch |
batch
|
protected Camera |
camera
|
protected float |
centerX
|
protected float |
centerY
|
protected float |
height
|
protected Group |
root
|
protected boolean |
stretch
|
protected float |
width
|
Constructor Summary | |
---|---|
Stage(float width,
float height,
boolean stretch)
Constructs a new Stage object with the given dimensions. |
Method Summary | |
---|---|
void |
act(float delta)
Calls the Actor.act(float) method of all contained Actors. |
void |
addActor(Actor actor)
Adds an Actor to this stage |
float |
bottom()
|
float |
centerX()
|
float |
centerY()
|
void |
clear()
Clears this stage, removing all Actor s and Group s. |
void |
dispose()
Disposes the stage |
void |
draw()
Renders the stage |
Actor |
findActor(java.lang.String name)
Finds the Actor with the given name in the stage hierarchy. |
java.util.List<Actor> |
getActors()
|
Camera |
getCamera()
|
java.util.List<Group> |
getGroups()
|
Actor |
getLastTouchedChild()
|
Group |
getRoot()
|
SpriteBatch |
getSpriteBatch()
|
java.lang.String |
graphToString()
|
float |
height()
|
Actor |
hit(float x,
float y)
Returns the Actor intersecting with the point (x,y) in stage coordinates. |
boolean |
isStretched()
|
boolean |
keyDown(int keycode)
Called when a key was pressed |
boolean |
keyTyped(char character)
Called when a key was typed |
boolean |
keyUp(int keycode)
Called when a key was released |
int |
left()
|
void |
removeActor(Actor actor)
Removes the given Actor from the stage by trying to find it recursively in the scenegraph. |
float |
right()
|
boolean |
scrolled(int amount)
Call this to distribute a mouse scroll event to the stage. |
void |
setCamera(Camera camera)
Sets the Camera this stage uses. |
void |
setViewport(float width,
float height,
boolean stretch)
Sets the viewport dimensions in device independent pixels. |
float |
top()
|
void |
toStageCoordinates(int x,
int y,
Vector2 out)
Transforms the given screen coordinates to stage coordinates |
boolean |
touchDown(int x,
int y,
int pointer,
int button)
Call this to distribute a touch down event to the stage. |
boolean |
touchDragged(int x,
int y,
int pointer)
Call this to distribute a touch dragged event to the stage. |
boolean |
touchMoved(int x,
int y)
Call this to distribute a touch moved event to the stage. |
boolean |
touchUp(int x,
int y,
int pointer,
int button)
Call this to distribute a touch Up event to the stage. |
void |
unfocusAll()
Unfocues all Actor instance currently focused. |
float |
width()
8 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected float width
protected float height
protected float centerX
protected float centerY
protected boolean stretch
protected final Group root
protected final SpriteBatch batch
protected Camera camera
Constructor Detail |
---|
public Stage(float width, float height, boolean stretch)
Constructs a new Stage object with the given dimensions. If the device resolution does not equal the Stage objects dimensions the stage object will setup a projection matrix to guarantee a fixed coordinate system. If stretch is disabled then the bigger dimension of the Stage will be increased to accomodate the actual device resolution.
width
- the width of the viewportheight
- the height of the viewportstretch
- whether to stretch the viewport to the real device resolutionMethod Detail |
---|
public void setViewport(float width, float height, boolean stretch)
width
- thew width of the viewport in device independent pixelsheight
- the height of the viewport in device independent pixelsstretch
- whether to stretch the viewport or notpublic float width()
public float height()
public int left()
public float right()
public float top()
public float bottom()
public float centerX()
public float centerY()
public boolean isStretched()
public Actor findActor(java.lang.String name)
Actor
with the given name in the stage hierarchy.
name
-
public java.util.List<Actor> getActors()
Actor
spublic java.util.List<Group> getGroups()
Group
spublic boolean touchDown(int x, int y, int pointer, int button)
touchDown
in interface InputProcessor
touchDown
in class InputAdapter
x
- the x coordinate of the touch in screen coordinatesy
- the y coordinate of the touch in screen coordinatespointer
- the pointer indexbutton
- the button that's been pressed
Actor
in the scene processed the event or notpublic boolean touchUp(int x, int y, int pointer, int button)
touchUp
in interface InputProcessor
touchUp
in class InputAdapter
x
- the x coordinate of the touch in screen coordinatesy
- the y coordinate of the touch in screen coordinatespointer
- the pointer indexbutton
- the button
Actor
in the scene processed the event or notpublic boolean touchDragged(int x, int y, int pointer)
touchDragged
in interface InputProcessor
touchDragged
in class InputAdapter
x
- the x coordinate of the touch in screen coordinatesy
- the y coordinate of the touch in screen coordinatespointer
- the pointer index
Actor
in the scene processed the event or notpublic boolean touchMoved(int x, int y)
touchMoved
in interface InputProcessor
touchMoved
in class InputAdapter
x
- the x coordinate of the touch in screen coordinatesy
- the y coordinate of the touch in screen coordinates
Actor
in the scene processed the event or notpublic boolean scrolled(int amount)
scrolled
in interface InputProcessor
scrolled
in class InputAdapter
amount
- the scroll amount.
Actor
in the scene processed the event or not.public boolean keyDown(int keycode)
keyDown
in interface InputProcessor
keyDown
in class InputAdapter
keycode
- one of the constants in Input.Keys
public boolean keyUp(int keycode)
keyUp
in interface InputProcessor
keyUp
in class InputAdapter
keycode
- one of the constants in Input.Keys
public boolean keyTyped(char character)
keyTyped
in interface InputProcessor
keyTyped
in class InputAdapter
character
- The character
public void act(float delta)
Actor.act(float)
method of all contained Actors. This will advance any Action
s active for an
Actor.
delta
- the delta time in seconds since the last invocationpublic void draw()
public void dispose()
dispose
in interface Disposable
public void addActor(Actor actor)
Actor
to this stage
actor
- the Actorpublic java.lang.String graphToString()
public Group getRoot()
Group
of this Stage.public SpriteBatch getSpriteBatch()
SpriteBatch
offers its Actor
s for rendering.public Camera getCamera()
Camera
of this stage.public void setCamera(Camera camera)
Camera
this stage uses. You are responsible for setting it up properly! The draw()
will call
the Camera's update() method and use it's combined matrix as the projection matrix for the SpriteBatch.
camera
- the Camera
public Actor getLastTouchedChild()
Actor
last hit by a touch event.public Actor hit(float x, float y)
Actor
intersecting with the point (x,y) in stage coordinates. Hit testing is performed in the order the
Actors were inserted into the Stage, last inserted Actors being tested first. To get stage coordinates from screen
coordinates use toStageCoordinates(int, int, Vector2)
.
x
- the x-coordinate in stage coordinatesy
- the y-coordinate in stage coordinates
public void toStageCoordinates(int x, int y, Vector2 out)
x
- the x-coordinate in screen coordinatesy
- the y-coordinate in screen coordinatesout
- the output Vector2
.public void clear()
Actor
s and Group
s.
public void removeActor(Actor actor)
Actor
from the stage by trying to find it recursively in the scenegraph.
actor
- the actorpublic void unfocusAll()
Actor
instance currently focused. You should call this in case your app resumes to clear up any pressed
states. Make sure the Actors forget their states as well!
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |