Actor Class of Libgdx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.