Hi guys, I’ve just started developing a small test project in Defold and I was having some trouble with GUI elements.
I’ve written a small script for a generic button that is going to handle things like animating when the mouse moves over it, etc.
If I place that GUI into a collection and run the game, it works.
If I place it as a template into a GUI and then place that GUI into a collection and run the game, it does not.
Do I need to write separate scripts to handle every piece of GUI? Or is what I’m trying to do possible. I could possibly do it by writing a static set of button functions for handling the animation, and then passing the desired gui nodes into that via a script but that seems odd.
I’m basically just trying to create a nice generic button that I can hook up to send whatever message I want to whatever game object I want.
Cheers
Adrian
edit: Ok I’ve discovered go.property, so that’s really useful! Is it possible to use this on gui_scripts? But I’m still wondering about running scripts on templates.
No, there is no notion of scripts belonging to nodes in Defold. Each instance of the template will have nodes named according to the template structure so you can definitely write generic code for any number of button instances, for example.
So the best way of doing this would be to write a module that handles all the animating/resizing/sound effects/etc for the buttons. And then in the GUI script just pass the nodes over to that?
Seems a bit odd but thanks for answering, I just wanted to make sure I hadn’t missed something obvious.