Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TouchScreenButton's "action" property doesnt work as intended on mobile. #58562

Open
doonv opened this issue Feb 26, 2022 · 24 comments
Open

TouchScreenButton's "action" property doesnt work as intended on mobile. #58562

doonv opened this issue Feb 26, 2022 · 24 comments

Comments

@doonv
Copy link

doonv commented Feb 26, 2022

Godot version

v4.0-alpha2

System information

Windows 10 64-bit, GPU: NVIDIA Geforce GTX 1650 Ti, CPU: AMD Ryzen 7 4800H

Issue description

I am porting my game to mobile devices. I need to make a button that would trigger a specific action on pressed. The action property seems to do exactly that. And it worked on PC! (with emulate_touch_from_mouse enabled) But on mobile, it doesn't work. It doesnt trigger the action when pressed. Nothing.

Steps to reproduce

See above

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Feb 26, 2022

@Dan-Gamin Please upload a minimal reproduction project to make this easier to troubleshoot.

Also, make sure Emulate Mouse From Touch is enabled in the project settings. See #24589.

@doonv
Copy link
Author

doonv commented Feb 26, 2022

Also, make sure Emulate Mouse From Touch is enabled in the project settings. See #24589.

@Calinou It is enabled. It works on PC. it doesnt work on mobile. I will add a minimal reproduction project soon.

@doonv
Copy link
Author

doonv commented Feb 26, 2022

@Calinou Well here the reproduction project.
TouchScreen.zip

But it works. But in my game. it doesnt.

@naithar
Copy link
Contributor

naithar commented Feb 26, 2022

Tested on iOS using alpha-3.
After touching white rectangle just pressed count increases and log displays InputEventAction: action="test_action", pressed=true.
Index is increasing the same way it does on M1 Mac. The only issue might be that for sore reason it is increased by 3 (on both macOS and iOS) due to the condition is_action_just_pressed triggering for InputEventAction, InputEventMouseButton and InputEventScreenTouch.

@doonv
Copy link
Author

doonv commented Feb 27, 2022

This is the scene tree of my mobile controls
image
The DashButton has a script because its a temporary solution to this problem.
The MobileControls node mainly controls the joystick.
Heres that MobileControls script:

extends CanvasLayer

@onready var _jinner: Sprite2D = $JoyStickAnchor/JoyStick/Inner

@onready var _jbutton: TouchScreenButton = $JoyStickAnchor/JoyStick
@onready var _jbutton_tex: Texture2D = _jbutton.texture_normal
@onready var _jbutton_center: Vector2 = _jbutton.position + (_jbutton_tex.get_size() / 2)
@onready var jmax_length: float = _jbutton_tex.get_width() / 2.0

var move_vector: Vector2 = Vector2.ZERO

var _jindex: int = -1



func _ready() -> void:
	visible = OS.has_feature("mobile")

func _input(event: InputEvent) -> void:
	if ((event is InputEventScreenTouch or 
			event is InputEventScreenDrag)
			and _jbutton.is_pressed() and 
			(_jindex < 0 or event.index == _jindex)):
		_jindex = event.index
		move_vector = point_to_move_vector(event.position)
		_jinner.position = (move_vector * jmax_length).limit_length(jmax_length - 10)
	elif event is InputEventScreenTouch and not event.pressed and (_jindex < 0 or event.index == _jindex):
		_jinner.position = Vector2.ZERO
		_jindex = -1
		move_vector = Vector2.ZERO

# Calculates the joystick move vector from a point
func point_to_move_vector(point: Vector2) -> Vector2:
	return ((point - _jbutton_center) / jmax_length).limit_length(1)

@naithar
Copy link
Contributor

naithar commented Feb 28, 2022

You should specify which mobile devices you've experienced this issue on.
As I mentioned iOS devices do not reproduce this issue with your current MRP.
You should probably also check other project settings or UI settings which could cause an issue to appear.

@doonv
Copy link
Author

doonv commented Feb 28, 2022

You should specify which mobile devices you've experienced this issue on. As I mentioned iOS devices do not reproduce this issue with your current MRP. You should probably also check other project settings or UI settings which could cause an issue to appear.

I am using Android.

@naithar
Copy link
Contributor

naithar commented Feb 28, 2022

@Calinou Well here the reproduction project. TouchScreen.zip

But it works. But in my game. it doesnt.

You should also update MRP so that it actually reproduces your issue if it doesn't. Because right now it's not doing it, at least on iOS and from what I understand you also can't reproduce an issue with this MRP.

@doonv
Copy link
Author

doonv commented Mar 9, 2022

I have minimized my game to only include the bug. It is reproduceable (at least for me on android).
Download the project here.

Edit: I forgot to explain how to reproduce the bug:
Basically, you have a little floating player which can move with the joystick. He can also dash. But he can't because the button is broken. Why doesn't he dash?

@naithar
Copy link
Contributor

naithar commented Mar 9, 2022

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

@akien-mga
Copy link
Member

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

@Dan-Gamin seems to have this issue on Android so I guess the iOS specific regression fix might not solve it?

@doonv
Copy link
Author

doonv commented Mar 9, 2022

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

Okay... I will test it out soon.

@doonv
Copy link
Author

doonv commented Mar 9, 2022

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

Okay... I will test it out soon.

It didn't fix it... I don't think this is related to multitouch since my dash should work without using the joystick (It remembers the last joystick vector).

Also, can anyone else reproduce this issue?

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

@Dan-Gamin seems to have this issue on Android so I guess the iOS specific regression fix might not solve it?

My bad. Seems like I've forgotten about it. 🤔

But I wasn't able to reproduce it in alpha-4. At least with the current project. I've had to modify it so it would actually run on new alpha release, I might have done something wrong though.

@doonv
Copy link
Author

doonv commented Mar 10, 2022

This is probably related to the #58550 and should be fixed by now. Please try using new Godot alpha 4 build.

@Dan-Gamin seems to have this issue on Android so I guess the iOS specific regression fix might not solve it?

My bad. Seems like I've forgotten about it. 🤔

But I wasn't able to reproduce it in alpha-4. At least with the current project. I've had to modify it so it would actually run on new alpha release, I might have done something wrong though.

@naithar This one.zip should actually reproduce the issue (even on 4.0.alpha4.offical). By pressing the virtual button on the right while moving. The player dashes, here is how that looks like (exaggerated on the given build for so you can see it better):
image

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

Right now I'm getting. And Spirit is not moving at all.

022-03-10 15:49:55.718494+0300 TouchScreenButton[1451:284049] USER WARNING: Cursor shape not supported by this display server.
2022-03-10 15:49:55.718558+0300 TouchScreenButton[1451:284049]    at: cursor_set_shape (servers/display_server.cpp:249) - Cursor shape not supported by this display server.

@doonv
Copy link
Author

doonv commented Mar 10, 2022

Right now I'm getting. And Spirit is not moving at all.

022-03-10 15:49:55.718494+0300 TouchScreenButton[1451:284049] USER WARNING: Cursor shape not supported by this display server.
2022-03-10 15:49:55.718558+0300 TouchScreenButton[1451:284049]    at: cursor_set_shape (servers/display_server.cpp:249) - Cursor shape not supported by this display server.

I have never seen that before... On which platform is this on?

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

iOS, that's the only mobile platform I can test

@doonv
Copy link
Author

doonv commented Mar 10, 2022

iOS, that's the only mobile platform I can test

Huh... On Android at least the Spirit moves. The Cursor shape not supported by this display server. warning is weird. It seems like its related to custom cursors but I haven't done that, nor is it possible for custom cursors on mobile. Is this maybe a separate issue?

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

After commenting out all cursor_set_shape usages, there is no problem on iOS:

IMG_7415.MP4

Edit:
Overriding cursor_set_shape method with empty method also helps for iOS.

@doonv
Copy link
Author

doonv commented Mar 10, 2022

After commenting out all cursor_set_shape usages, there is no problem on iOS:

IMG_7415.MP4
Edit: Overriding cursor_set_shape method with empty method also helps for iOS.

Where? They are no cursor_set_shape usages in my code.
image

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

After commenting out all cursor_set_shape usages, there is no problem on iOS:
IMG_7415.MP4
Edit: Overriding cursor_set_shape method with empty method also helps for iOS.

Where? They are no cursor_set_shape usages in my code. image

In engine code.

@doonv
Copy link
Author

doonv commented Mar 10, 2022

In engine code.

Interesting... Maybe that fixed the problem? When I run my game on android, I get this warning:

W 0:00:02:0196   set_icon: Icon not supported by this display server.
  <C++ Source>   servers/display_server.cpp:320 @ set_icon()

Maybe this is the cause since it comes from the same source script that caused your issue?

@naithar
Copy link
Contributor

naithar commented Mar 10, 2022

In engine code.

Interesting... Maybe that fixed the problem? When I run my game on android, I get this warning:


W 0:00:02:0196   set_icon: Icon not supported by this display server.

  <C++ Source>   servers/display_server.cpp:320 @ set_icon()

Maybe this is the cause since it comes from the same source script that caused your issue?

I guess it could be related, but I have no means to check android version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants