"Open source Java Game Framework Libgdx theme" -15-System control-button class

Source: Internet
Author: User
Tags libgdx

The button class inherits from the actor class and can be used on the stage, but it also inherits the subclasses of many actors, such as group, Table, Widgetgroup lights. Commonly used Construction methods: button (): Create buttons object, do not set its style and size button (Button.buttonstyle style): Create a button, parameter is the size of the specified button and Style button (drawable up) : Creates a button object, when the button is not clicked (that is, the lift state), the style is within the parameter Texture Style button (drawable up,drawable down): Creates a Button object, the first parameter represents the lifted state using the up texture, The second parameter represents the pressed state when using the down texture button (drawable up,drawable down): Creating the Button object, the 12th argument above, and the third parameter representing the texture button used when the mouse is over the button (skin skin): Create a Button object, Use the Style button in the Skin object (skin skin,string stylename): Use the style of the buttons with the name specified in the Skin object. Common method: Draw (Batch batch,float Parentalpha): Draws the current button. The first parameter represents the sprite brush you want to draw, the second parameter represents the current button's Transparency Getclicklistener (): Gets the listener added by the current button Getminhight (): Gets the button min height getminwidth () : Get button min width invalidate (): void current Layout invalidatehierarchy (): Void the current actor and all of its parent layout (): Calculates the drawing information for all actors in the current layout pack () : Arranges the width and height information of the current actor and selects the optimal width and height setfillparent (boolean fillparent): Fills the current area setlayoutenabled (Boolean enabled) : Whether to use the current layout with the current actor and its subclasses validate (): Determines whether the current actor has been layout Common properties: checked: Mouse over button explicit texture, return type drawablecheckedover: Mouse over button and leave button explicit texture object , returns the drawable type down: The texture that is displayed when the button is pressed, returns the drawable type PRESSEDOFFSETX: Click the x-axis offset of the mouse for the current button pressedoffsety: Click the y-axis of the current button's mouseShift UNPRESSEDOFFSETX: The x-axis offset of the mouse leaving the current button unpressedoffsety: the y-axis offset of the mouse that left the current button up: The texture that is displayed when the button is not pressed, the return type is the drawable type variable code:
1    PackageCom.mygdx.syscontrol;2 3 Importcom.badlogic.gdx.scenes.scene2d.InputEvent;4 ImportCom.badlogic.gdx.scenes.scene2d.utils.ClickListener;5 /**6 * My Click event class7  * @authorJack (Le Zhi)8 * @blog dtblog.cn9 * @qq 984137183Ten  */ One  Public classMyclickextendsClicklistener { A  - @Override -      Public BooleanTouchDown (InputEvent event,floatXfloatYintPointerintbutton) { the         //Print -System.out.println ("button:" +button); -         return true; -     } +  -}

1  PackageCom.mygdx.syscontrol;2 3 ImportCom.badlogic.gdx.ApplicationAdapter;4 ImportCom.badlogic.gdx.Gdx;5 Importcom.badlogic.gdx.graphics.GL20;6 Importcom.badlogic.gdx.graphics.Texture;7 Importcom.badlogic.gdx.graphics.g2d.TextureRegion;8 ImportCom.badlogic.gdx.scenes.scene2d.Stage;9 ImportCom.badlogic.gdx.scenes.scene2d.ui.Button;Ten ImportCom.badlogic.gdx.scenes.scene2d.ui.Skin; One Importcom.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; A /** - * Use button -  * @authorJack (Le Zhi) the * @blog dtblog.cn - * @qq 984137183 -  */ -  Public classTestbuttonextendsApplicationadapter { +     //Declaring skin Objects -     Privateskin skin; +     //Declare button a A     PrivateButton Buttona; at     //Declare button b -     PrivateButton buttonb; -     //declaring the stage -     PrivateStage stage; -     //The texture when the button is lifted -     PrivateTexture Btnup; in     //Texture When the button is pressed -     PrivateTexture Btndown; to     //declaring listeners +     PrivateMyclick click; -      the @Override *      Public voidCreate () { $         //instantiate a Skin objectPanax Notoginsengskin=NewSkin (Gdx.files.internal ("Button/test.json")); -         //Instantiate the stage theStage=NewStage (); +         //Initialize button lift Texture Abtnup=NewTexture (Gdx.files.internal ("Button/btnup.png")); the         //Initialize the button to press the texture +btndown=NewTexture (Gdx.files.internal ("Button/btndown.png")); -         //Lift Texture Style $Textureregiondrawable btn_up=NewTextureregiondrawable (Newtextureregion (Btnup)); $         //Press the texture style -Textureregiondrawable btn_down=NewTextureregiondrawable (Newtextureregion (Btndown)); -         //Instantiate button a theButtona=NewButton (Skin.get ("style", Button.buttonstyle.class)); -         //Initialize button bWuyibuttonb=NewButton (btn_up,btn_down); the         //Initial Knowledge Listener -click=NewMyclick (); Wu         //Add Listener - Buttona.addlistener (click); About Buttonb.addlistener (click); $         //set the position of button B -Buttonb.setposition (100, 100); -         //Add a button B to the stage - Stage.addactor (BUTTONB); A         //Add a button A to the stage + Stage.addactor (Buttona); the         //register for stage monitoring - Gdx.input.setInputProcessor (stage); $     } the  the @Override the      Public voidrender () { theGdx.gl.glClearColor (1, 1, 1, 1); - Gdx.gl.glClear (gl20.gl_color_buffer_bit); in         //Update Stage Logic the stage.act (); the         //Draw Stage Content About Stage.draw (); the     } the  the}

Resource path:: The original written by Bo Master Le Zhi Editor, the copyright belongs to the owner of the blog. The original address http://www.dtblog.cn/1170.html reprint please specify the source!

"Open source Java Game Framework Libgdx theme" -15-System control-button class

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.