You are viewing a single comment's thread from:

RE: Tutorial (Godot Engine v3 - GDScript) - GUI for score & lives!

in #utopian-io7 years ago

Did a bit of reading in the docs. Following was separated among several articles lol. Parenting your Control nodes(all ui elements are control nodes) to a node 2d wont change performance, you are just giving your ui to world space. It doesnt really make sense to structure your scene like that.

Control is not heavier unless you are doing some really wierd input handling in your gui

  1. _input() is called on every node in the scene until it is consumed ("SceneTree.set_input_as_handled ( )")

  2. _gui_input() is called second if the input is still unhandled and is special because it is called only when

-The mouse pointer is over the control.
-The button was pressed over this control (control always captures input until button is released)
-Control provides keyboard/joypad focus via Control.focus_mode.
Also similar to node: you only need to override _gui_input()

Control has a method accept_input() which stops the event propagation

3~ if the event remains unhandled then

_unhandled_input() is called.

Godot's docs recommend implementing gameplay input in this method to allow the gui to intercept events. Example: mouse click on a menu item wont propogate to actual 3d or 2d objects behind the menu, or if your menu pop up you can handle input through the menu. FYI if you overrode _gui_input() and its childed to a node 2d, _gui_input() is still being called.

Usually I only see people implement _input(event) for games like your space invaders. _unhandled_input is probably best for mouse clicks.

Theres way more specifics, here is some of the docs I referenced,





http://docs.godotengine.org/en/3.0/tutorials/inputs/inputevent.html#how-does-it-work http://docs.godotengine.org/en/3.0/classes/class_node.html#class-node-unhandled-input http://docs.godotengine.org/en/3.0/classes/class_control.html?highlight=gui_control#id1 http://docs.godotengine.org/en/3.0/tutorials/gui/custom_gui_controls.html#input http://docs.godotengine.org/en/3.0/classes/class_scenetree.html#class-scenetree-set-input-as-handled

Sort:  

Wow! Thanks Wolf for taking the time to provide the response! I can understand from the above a reason to use Control. My need was only for a parent container for the TitleValues. I wasn't looking to try to find the perfect answer :-). My concern is that worrying to such low detail is expending energy on something that makes no real impact on the final delivery. IF I worried about every little aspect like this, I'd never write code; I don't want to sound arrogant or flippant; what I'm trying to say is, YES, you are correct. If I were building a large GUI will buttons and controls, then using the Control as a parent would make more sense. However, it is just a simple container to hang the TitleValue's of. I'll happily change it to control now, going forward, but in the scheme of things, it isn't important.

In fact, I've just changed the node to Control; this then breaks the game.

Control doesn't have all the positioning on the screen, i.e. Z-Index. Therefore I now would have to create a Canvas too and then set priorites; but with that, I lose visibility!

Yeah, takes some fiddling to get stuff to work right. Appreciate your responses, I never really understood how Godot handles is beyond a "it just works" explanation.

Why I resorted to writing some scenarios and try to explain the thinking because it is this experience that I think is invaluable to a learner. I really love Godot and the way it is designed for scripting etc, but it can be frustrating too, when you know you want something simple, but have to bend and shape as you require. I.E. The physics engine in is great, but it has so many unresolved issues because it is trying to be general to all, but is actually specific to its implementation (if you know what I mean)

Hey @sp33dy I thought I'd share this. The camera in this game moves, so using a canvas layer is a necessity. I found this method simple for hiding unnesacary nodes for the scene and keep it simple and clean. All you need to do is save your canvas layer as a packed scene.

Screenshot (19).png

@Wolfwin, I was meant to respond to you. I do like the idea of saving the packed scene, but it still didn't provide a way for me to hide the UI via the visible flag. Thanks for the heads-up.