|Topic was automatically imported from the old Question2Answer platform.
I’m a business developer. I don’t think in scenes. I think in terms of objects and inheritance.
I was surprised that Godot globally handles all events on all objects. Even the 2D Buttons do not limit themselves to clicks just within their rectangle. A single mouse click being handled by each object, even when the mouse is not in the rectangle for the object.
Instead, it seems I have to calculate for every object in my application whether or not a particular click was meant for it or not. Meaning, I gain nothing from having Buttons vs Node2D, and meaning I have to a lot of low level work, things I would reject from any business developer. (In principle, if it seems like you’re doing too much work, either you or the system is broken.)
If there’s a better way, I’d like to learn, because I do appreciate being able to export to Android from this platform.
“and meaning I have to a lot of low level work” - you don’t have a lot of low level work, quite the opposite - Godot is the clearest and easiest one in that concern. If you attach a script in a Button, for example, you will catch only the events from that Button and its sub nodes, and only the events that you want. Also, have you looked at Signals?
alfredbaudisch | 2019-03-31 18:53
signals will definitely help me with the next issue I will face. I appreciate the direction.
At the moment, I have 19 card items when I start my application. Each one inherits from my card scene with an attached script. The _input responds even when I click on empty space. So, I tried adding a Button to the scene and moving the _input to the Button, except, as mentioned, the script responds to all events that the application does, and worse it fires 19 times (once for each card scene on the table.)
Again, you’re right, I will later want to signal a specific clicked or tapped/touched card to the main scene. But for now, my issue is that since the click isn’t handled the way HTML (for example) would, I have to calculate if my mouse was in the scene, the location of my relative scene to the root, the mouse coordinates, the bounds of my scene, whether two scenes might have received the click I wanted, etc.
This is all doable but cumbersome, and by virtue of being cumbersome, it means either I am doing something really stupid (which I hope to learn from) or else that this platform is not right for my needs.
grendahl06 | 2019-03-31 19:07
“I have to calculate if my mouse was in the scene, the location of my relative scene to the root, the mouse coordinates, the bounds of my scene” - not at all! It is as simply as connecting the on_pressed signal for a given button, for example. Just click HTML onClick Do like this: add a Button or TextureButton → click its node → the in the inspector go to the Node tab → double click the pressed() signal → assign a function. Done. Maybe even easier than HTML?
alfredbaudisch | 2019-03-31 19:13
If you’ll add this as an answer, I will mark it as answered. I’m very spoiled by the reflection in Visual Studio, but when I had to switch to GD script (or thought I had to?), I lost the useful intellisense. Godot is picky about when it will and won’t show me help. I’ve been using the _input, expecting this was the only way objects handled input events. I’m still bothered that this assumption wasn’t right, but at least you’ve solved my current and next design blocks. Thanks.
grendahl06 | 2019-03-31 19:34