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?

+8 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 (3,748 points)

2 Answers

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


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


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 (1,988 points)
selected 2 days ago 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 (2,874 points)