Godot Version
4.4.1.stable
Question
I know that TouchScreenButton node exists but I just wanna know if there’s a way to implement touch screen input on TextureButton in code to load a scene. It works on Button node when I set “Emulate Mouse From Touch” to On but somehow it doesn’t work on TextureButton node. Also, I got this Error
because I have a “Virtual Joystick” addon by MarcoFazio installed.
* Error: The Project Setting "emulate_mouse_from_touch" should be set to False
Script are the following:
extends Control
# Signals TextureButton node
func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file("res://main.tscn")
# Signals Button node
func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file("res://main.tscn")
And this is my attempt so far:
extends Control
# Signals TextureButton node
func _on_play_button_pressed(event) -> void:
if event is InputEventScreenTouch:
if event.pressed():
get_tree().change_scene_to_file("res://main.tscn")
# Signals Button node
func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file("res://main.tscn")
All Button & TextureButton settings are default.
Should work fine with the textureButton as well, make sure your signal is connected properly.
Also the error is from the virtual joystick’s code.
I have also used that plugin before. You could just comment out the lines that throws the error and everything should still work fine
Comment out these line to get rid of the error
1 Like
I just wrote you a long answer and realised finally what you are asking. I think it is "how do I detect a mouse touch on a texture button if emulate_click_from_touch is disabled? Is that right?
You were almost there, but the InputEventScreenTouch has pressed as a property not a method. So just drop the brackets.
func _on_play_button_pressed(event: InputEvent) -> void:
if event is InputEventScreenTouch and event.pressed:
get_tree().change_scene_to_file("res://main.tscn")
In the docs:
PS If you are going to use the excellent plugin from MarcoFazio you should set the emulators as he suggested, with touch from click enabled, and click from touch disabled. Otherwise you could get some unexpected behaviour.
PPS I also presume that you are correctly using the _gui_input() signal, not the pressed signal as this does not have the event sent in the signal.
func _on_texture_button_gui_input(event):
1 Like
Thank you very much! It worked!
1 Like