Stage class of Libgdx

Source: Internet
Author: User
Tags libgdx

Total List of tutorials: http://blog.csdn.net/zqiang_55/article/details/50878524

Previously said in Libgdx painted pictures of the spritebatch and stage class, now to explore stage class.
In fact, the stage inside the default will initialize a Spritebatch,stage main work is to draw UI elements, including image, Label, button, and so on, before continuing to understand, let's look at a picture, the UI is mainly in accordance with this picture to explain

Description of the Stage class:


First, the coordinate origin used by the stage starts from the lower left of the screen, which shows that viewport and batch are in the stage.

The source code shows that the Act (float Delta) and draw () methods are notifications of objects added to the actor to perform their respective act () and Draw () methods. In particular, the Setdebugall method, which allows each actor in the stage to add a wireframe, facilitates debugging

Monitoring stage

In fact, to LIBGDX monitoring stage method is very simple, through the above class diagram can see the stage inherits from Inputadapter, so through Gdx.input.setInputProcessor

Double Stage

In fact, the use of the stage can not only achieve double stage, the same principle can achieve multi-stage. In the game design process, such as some of the options window, stores and the like can be implemented on the stage.
In addition, some simple games, you can design only one gamescreen, the rest of the parts are presented to different stage to show, for example:

Test code
Mystage Mystage;    Stage stage;    Bitmapfont font;    LabelStyle style; Label Stagelabel;Booleanisstagevisiable;@Override     Public void Create() {Viewport Viewport =NewStretchviewport (Gdx.graphics.getWidth (), Gdx.graphics.getHeight ()); Viewport.apply (true); Font =NewBitmapfont (); style =NewLabelStyle ();        Style.font = font; Mystage =NewMystage (viewport);        Gdx.input.setInputProcessor (Mystage); Stagelabel =NewLabel ("Stage:click me to change Stage", style); Stagelabel.setx (Gdx.graphics.getWidth ()/2-Stagelabel.getwidth ()/2); Stagelabel.sety (Gdx.graphics.getHeight ()/2-Stagelabel.getheight ()/2); Stagelabel.addlistener (NewClicklistener () {@Override             Public void clicked(InputEvent event,floatXfloatY) {if(!mystage.getvisiable ()) {isstagevisiable =false; Mystage.setvisiable (true);                Gdx.input.setInputProcessor (stage);        }            }        }); stage =NewStage (viewport);        Stage.addactor (Stagelabel); Isstagevisiable =false; }@Override     Public void Render() {Gdx.gl.glClearColor (0.39F0.58F0.92F1.0f); Gdx.gl.glClear (Gl20.gl_color_buffer_bit);if(isstagevisiable)            {stage.act ();        Stage.draw (); }if(Mystage.getvisiable ())            {mystage.act ();        Mystage.draw (); }    }@Override     Public void Dispose() {stage.dispose ();        Mystage.dispose ();    Font.dispose (); } Public  class mystage extends Stage {Texture Texture;        Image img; Label Mystagelabel;Booleanismystagevisiable; Public Mystage(Viewport Viewport) {Super(viewport); Texture =NewTexture ("Badlogic.jpg"); IMG =NewImage (texture); Img.setx (GetWidth ()/2-Img.getwidth ()/2); Img.sety (GetHeight ()/2-Img.getheight ()/2);            Addactor (IMG); Mystagelabel =NewLabel ("Mystage:press C to change stage", style);            Mystagelabel.setx (Img.getx ()); Mystagelabel.sety (img.gety () + img.getheight () +Ten);            Addactor (Mystagelabel); Ismystagevisiable =true; }@Override         Public void Dispose() {Super. Dispose ();        Texture.dispose (); } Public Boolean getvisiable() {returnismystagevisiable; } Public void setvisiable(Booleanvisiable) {ismystagevisiable = visiable; }@Override         Public Boolean KeyDown(intKeyCode) {if(keycode = = KEYS.C) {isstagevisiable =true; Ismystagevisiable =false;            Gdx.input.setInputProcessor (stage); }return Super. KeyDown (KeyCode); }    }

Stage 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.