I am planning to implement chat bubbles above the heads of my actors. I could start hacking away and come up with a solution but wanted to gather some thoughts from others who may have implemented something similar with libGDX and get some recommendations on the best approach.
#1 - Use a custom draw method that autosizes itself and appears on screen using offsets from the player character and/or npc who is speaking. This would be easy to hack together, but could be challenging coming up with custom text wrapping and would take extra work to make the bubble actually look good.
#2 - Use a label widget from scene2d. I could add a label to the scene table that remains above the player’s head but is invisible until text is ready to be shown. A timer could easily hide the box again after a few seconds. This seems reasonable for the player character but may not work for other non player characters on the screen. If you had one other NPC on screen who is speaking you could find his location and set the position of the label prior to unhiding it. However, what if you had 10 NPCs on screen who are talking? You would need 10 hidden labels just sitting around and whenever text needs to be shown iterate over the list of labels, grab the first unused label, set its position and text, then hide and release it when finished.
#3 - Similar to approach #2 but dynamically create and destroy a label for every message. This seems to make the most sense in theory but I’m not sure if creating and destroying labels frequently is an intended use of scene2d widgets.
Regardless of the approach another consideration would be the ability to move the chat bubble as an actor moves (like chat bubbles did in Ultima Online). With this in mind it seems like I should create a new label widget within the scope of my actor class where I can retain both the position of the actor and where the label should be at any given time.
From the scene2d wiki:
“Widgets can be used as simple actors in scene2d, without using tables or the rest of scene2d.ui. Widgets have a default size and can be positioned absolutely, the same as any actor.”
Thoughts or recommendations?