I’m pretty new to game dev, so I’m just looking for a sanity check on my GUI / screen handling method. Any additional feedback would be great as well.
For background, I’m making a business sim / tycoon type game and, at the moment, most of the game takes place in GUI Scenes. There will be some regular game scenes for later action/physics elements, but that’s a minority of the game – most of the game is GUI.
It seems that most people like to use collection proxies for screen switching, but since I’m bouncing back between many GUI screens and don’t need the duplicate game worlds from proxies, I wanted to save the resources overhead so I figured I would use collection factories instead.
As I have it set up now, my main collection has a home screen GUI and a loader GO which hosts the collection factories from the various other GUIs.
Right now, the loader creates the other GUIs on init, and gets the hash URL from the generated table for later use. (side bar: I remember reading somewhere that something with URLs is disabled at bundling… would this be affected?)
function init(self)
--create instance from collection factory, then get hash from table and save to variable
local gui_menu2_table = collectionfactory.create("loader#gui_menu2")
self.gui_menu2 = gui_menu2_table[hash("/gui_menu2")]
When the user presses a button on the home screen, the home screen sends a message to the loader, the loader then calls a simple function which, for now, forwards the message along to the target GUI.
-- onmessage call "show" function
function on_message(self, message_id, message, sender)
if message_id == hash("show_gui_menu2") then
show_gui_menu2(self)
end
end
--show function sends simple show message to target
local function show_gui_menu2(self)
msg.post(self.gui_menu2, "show_gui_menu2")
end
I have it set up this way in case I decide to remove the GUIs from creating at loader init later on: e.g., I could easily switch to async loading or load resources on startup but only create when first called, or otherwise only load on first call, if the game starts running slowly later in development.
I could also easily swap out a collection factory for a collection proxy for certain calls if I need a game world later.
A couple questions I have:
- Is there a better way to do this?
- Am I overthinking the collection proxy issue?
- Am I overthinking the message passing to the generated GUIs?
- Is there a simpler function to get the hashed URL in one step rather than get the table, then convert?
- Should I be unloading / deleting the factory-generated GUIs whenever they hide? I’m not sure how much memory that would save. They aren’t that complex at the moment.
I know my current code works on build to swap between GUIs, but my game is currently pretty empty anyway. I’m hoping it scales as my game grows and uses less resources than if I had used collection proxies due to less overhead.
I suppose I could probably make the loader a more generic message forwarder too, to send any message to the factories instead of just the ones the loader is programmed for.
The game is very early in development so I’m basically just writing the gui / screen handlers at the moment while I work out the core game mechanics in blocks / pseudo-code.
Another option, I guess, is just to throw everything in the main collection but then I have no control over dynamic loading if things get slow, and everything is just overlaid in the defold window.
And the last option is to stop trying to reinvent the wheel and just use collection proxies like everyone else.
Thoughts?