Total List of tutorials: http://blog.csdn.net/zqiang_55/article/details/50878524
In the previous article we introduced the Libgdx stage class, according to the class inheritance diagram, we should introduce the actor class, from which we know that the UI controls in Libgdx are inherited from the actor.
We have also introduced the Sprite class, the actor is a bit like the Sprite class, save position, size, color, rotation center, zoom and actions, but also contains a stage class. the actor's coordinate system (local coordinate) is calculated from the lower left corner
We can set listener to handle some listening events when we initialize the actor.
Note: 1. The draw function of the actor is empty by default and needs to be rewritten.
2./** called by the framework, the this actor, or any parent are added to a group, that's in the stage.
* @param stage may be null if the actor or any parent is no longer in a stage. */
protected void Setstage (stage stage) {
This.stage = stage;
}
3. In addition, there is a function to note:
/* Set bounds the x, Y, width, and height. /
public void SetBounds (float x, float y, float width, float height)
Test code:
Stage stage; Myactor Myactor;@Override Public void Create() {stage =NewStage (); Gdx.input.setInputProcessor (stage); Myactor =NewMyactor (); Yactor.setx (Gdx.graphics.getWidth ()/2-Myactor.getwidth ()/2); Myactor.sety (Gdx.graphics.getHeight ()/2-Myactor.getheight ()/2); Stage.addactor (Myactor); }@Override Public void Render() {Gdx.gl.glClearColor (0.39F0.58F0.92F1.0f); Gdx.gl.glClear (Gl20.gl_color_buffer_bit); Stage.act (); Stage.draw (); }@Override Public void Dispose() {stage.dispose (); Myactor.dispose (); } Public class myactor extends Actor implements disposable {Textureregion region; Public Myactor() {region =NewTextureregion (NewTexture ("Badlogic.jpg")); SetSize ( This. Region.getregionwidth (), This. Region.getregionheight ());//Set up a listener function that can handle some thingsAddListener (NewClicklistener () {@Override Public void clicked(InputEvent event,floatXfloatY) {//Click on picture, image hidden! [Write a description of the picture here] (http://img.blog.csdn.net/20160425220710777)SetVisible (false);Super. clicked (event, X, y); } }); }@Override Public void Draw(Batch batch,floatParentalpha) {Super. draw (Batch, parentalpha); Batch.draw (Region, GetX (), GetY (), Getoriginx (), Getoriginy (), getwidth (), Getheig HT (), Getscalex (), Getscaley (), getrotation ()); }@Override Public void Dispose() {region.gettexture (). Dispose (); } }
Actor Class of Libgdx