Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

How do we add pop-ups (Dialog) in libGDX?

+11 votes
We have not yet been able to create a Dialog object without throwing an exception. Can someone explain or recommend a simple tutorial explaining how to use these?
asked Oct 12 in CSC 285 (F17) by Vecna (100 points)

3 Answers

+2 votes
 
Best answer
We got Dialog objects to work today in class! I found the top answer in this link particularly helpful:

https://gamedev.stackexchange.com/questions/84373/how-do-i-make-a-pop-up-window-with-scene2d

I also used this link that describes what each method does in the Dialog class:

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Dialog.html

In your code where you are about to change slides when clicking an ActionChoice you should add some logic that calls a method that displays the dialog object if you need to. Then the code creating the dialog object is in a separate method. You can set the text of your pop-up by passing you message in as a string to the text method. We just created an OK button using one of the button methods. We passed in our Dialog object as a parameter because that is the Object passed in for the result method. You have to do this because this method is outside of the scope where your dialog object exists. Since objects are passed by reference, it will do any effects that you do within the method on the object that you pass in. We just did dialog.hide() in the result method to hide the dialog message when you click OK. Hope this helps. Let me know if you have any other questions.
answered Oct 13 by Samuel Totten (100 points)
selected Oct 18 by Vecna
+1 vote
We're thinking about using a special type of Slide to display historical notes and ActionChoice rejection messages instead, since we haven't been successful using the Dialog object in LibGDX yet... Anyone else taking this approach?
answered Oct 13 by Christian Elliott (100 points)
+1 vote
Dialog dialog = new Dialog("", skin)  should initialize it, and then you can do things such as dialog.button(String, boolean) and set the text like dialog.text(String). You just have to make sure to show it at the end by using dialog.show(your stage).
answered Oct 25 by Paige Oucheriah (100 points)
...