LIBGDX provides window classes (Windows) for developers to prompt users, or to perform some input operations.
Window can be dragged by clicking on the title, or it can be set to modal mode. Preferred size is determined by both the title text and the actor loaded inside, and the size is recalculated when the pack method is called.
Dialog extends window, Dialog is a modal window (Modal Windows) that provides the content table and button table, which makes it easy to find the added text in Dialog. when the button is clicked, the result method is called, and dialog automatically disappears
Here is the code time, you can run the code to see the effect:
Window window;Dialog Dialog;Textbutton Tbok, Tbcancel;Stage Stage;Skin Skin;@Override public void Create () {stage = new stage ();Gdx. Input. Setinputprocessor(stage);Skin = new Skin (GDX. Files. Internal("Uiskin.json"));window = New Window ("Windowtest", skin);The default text is displayed on the left, and you need to manually set the center window. Gettitlelabel(). Setalignment(Align. Center);The default window is located in the lower left corner, and you need to reset the window. SetX(GDX. Graphics. GetWidth() /2-Window. GetWidth() /2);Window. Sety(GDX. Graphics. GetHeight() /2-Window. GetHeight() /2);Dragging the Titlelabel,window will move the window. Setmovable(false);Tbok = new Textbutton ("OK", skin);Tbcancel = new Textbutton ("Cancel", skin);Tbok. SetSize(Tbcancel. Getprefwidth(), Tbcancel. Getprefheight());Tbcancel. AddListener(New Clicklistener () {@Override public void clicked (InputEvent event, floatx, floaty) {window. setvisible(false);} });Tbok. AddListener(New Clicklistener () {@Override public void clicked (InputEvent event, floatx, floaty) {GDX. App. Log("TAG","dialog OK button is clicked");} });Tbok. SetX(Window. Getprefwidth() /2-Tbok. GetWidth() /2-Ten);Tbok. Sety(Ten);Tbcancel. SetX(Window. GetWidth() /2+Ten);Tbcancel. Sety(Ten);This place is used Addactor method, cannot useAddmethod, the table will be explained later when the window is involved. Addactor(Tbok);Window. Addactor(Tbcancel);Gdx. App. Log("TAG","Window prewidth="+ window. Getprefwidth() +"Window width="+ window. GetWidth());Window. Pack();Stage. Addactor(window);Dialog = New Dialog ("Dialogtest", Skin,"Dialog");Dialog. Gettitlelabel(). Setalignment(Align. Center);This does not get OK Event//Add text message (label form) to Dialog dialog. Text("This is Test information");Add buttons to dialog (button form), dialog automatically disappear after clicking the button//dialog. Button("OK", true). AddListener(New Clicklistener () {////@Override//public void clicked (InputEvent event, floatx, floaty) {//GDX. App. Log("TAG","dialog OK button is clicked");// }// // });This method is as effective as the above method dialog. Button(Tbok);Dialog. Setmovable(false);Stage. Addactor(Dialog);} @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();Skin. Dispose();}
LIBGDX window Dialog Windows and dialog boxes