Using the window hierarchy
A basic game UI can be constructed with a bunch of windows that are on the same level. There might be occasions where you'll need more complex UI with layered windows. You can observe this kind of UI in many modern window managers or web browsers. Windows can contain other windows or user controls. If you move the main window, it will also move inner elements with it. This behavior is done with the window hierarchy.
Getting ready
Implementing the window hierarchy system requires a well-defined data structure design, as well as correct use of matrix transformations.
This recipe will use a simple graph structure that consists of nodes and a list of child nodes. You can implement this structure in the Lua language with tables:
local main_window = { properties = {}, children = { { properties = {}, children = {}, }, -- ... }, }
In this case, each node contains window properties and a list of children windows. With this design, you can traverse...