Godot: Touchscreen button doesn't obey control positioning

Created on 5 Mar 2014  Â·  8Comments  Â·  Source: godotengine/godot

Hi
found a little thing:
the touchscreen button is missing the layout features found in other controls, and controls having specific layout (as the centercontainer) don't act upon it

as the other button lacks the passby press feature, I am currently work around it with a texture button and handling the press flag myself capturing scroll in, scroll out and pressures:

sample code:

func _input(event):
  if (event.type == 3 || event.type == 6 ):
    var button_rect = Rect2(get_node("LControl/Button").get_global_pos(), get_node("LControl/Button").get_size())     
    if (button_rect.has_point(event.pos)):
      button_pressed = event.is_pressed()
  if (event.type == 7 ):
    var button_rect = Rect2(get_node("LControl/Button").get_global_pos(), get_node("LControl/Button").get_size())
    if ( (!button_rect.has_point(event.pos)) and button_rect.has_point(event.pos-event.relative_pos) ):
      button_pressed=false
    if ( (button_rect.has_point(event.pos)) and !button_rect.has_point(event.pos-event.relative_pos) ):
      button_pressed=true
bug core

Most helpful comment

I know this is not a big bug, but it really bothers me.
It really doesn't make sense to me why TouchScreenButton is a Node2D instead of Control.

As it's written in the latest documentation,
Node2D:

A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.

Control:

All User Interface nodes inherit from Control. A control’s anchors and margins adapt its position and size relative to its parent.

And just the word _BUTTON_ makes me think that TouchScreenButton should fall in the "User Interface" category.

Also, as I understand, Node2D nodes should only be used in 2D games, and TouchScreenButton might be needed in both 2D and 3D games.

All 8 comments

Can someone confirm this issue in the current master branch?

Ping :)

TouchScreenButton is not inheriting from ControlNode so the issue is still correct. However I'm unsure about bug status, since TouchScreenButton is not a Control by design, so it's hard to demand from it to behave like a Control node.

I think we should close this or convert to feature request, what do you think @akien-mga ? I personally would prefer to close since I'm unsure if there really is demand for this functionality (and if it's then we will have feature request soon anyway). Also other control nodes probably behave little different today on touch screens then they were in 2014 so I'm unsure how much usage needs TouchScreenButton meets in present times anyway.

As there as not been any activity on this issue in two years, neither from the reporter or from other interested users, I think we can close it indeed. If there's a need in the current 2.0 version, someone will open a feature request.

Ah I fixed this some months ago, forgot to close it

On Tue, Mar 8, 2016 at 9:15 AM, Rémi Verschelde [email protected]
wrote:

Closed #171 https://github.com/godotengine/godot/issues/171.

—
Reply to this email directly or view it on GitHub
https://github.com/godotengine/godot/issues/171#event-581644721.

Hi . It works .. when inside a simple container (It will work in any others too like HBox or VBox but they are overkill)..
Solution 1.
Add a VBox, add few simple containers as children and one touch screen button as child of each container . And voila . You have control obeying touch screen buttons !! Maybe this may be just a temporary workaround but works for now and I am happy with the results. note that container should have min and max width set at 0 for it to work properly . also the buttons go the other way around , for me at least .. but no they will follow the normal control workflow and change layout automatically depending on which container they are in.

edit: it's just a hack, as positioning only works upto an extent!!

Solution 2 modification of solution 1 (better control)
Edit: better way would be to to put all touchscreen buttons inside a control like hbox or vbox or something better, maybe just a simple container ??, but they will be on top of each other even if you use hBox or vBox, but they will stay inside the container no matter what, then you can use internal positioning for the children touchscreen buttons ! (Note you need to set the min width or height of the vBox or hBox elements).

I know this is not a big bug, but it really bothers me.
It really doesn't make sense to me why TouchScreenButton is a Node2D instead of Control.

As it's written in the latest documentation,
Node2D:

A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.

Control:

All User Interface nodes inherit from Control. A control’s anchors and margins adapt its position and size relative to its parent.

And just the word _BUTTON_ makes me think that TouchScreenButton should fall in the "User Interface" category.

Also, as I understand, Node2D nodes should only be used in 2D games, and TouchScreenButton might be needed in both 2D and 3D games.

Was this page helpful?
0 / 5 - 0 ratings