Topic was automatically imported from the old Question2Answer platform.
Asked By
mydoghasworms
Old Version
Published before Godot 3 was released.
I am getting started in Godot and trying to write a simple game, where, when you tap the screen and hold down, the player should be running.
This works fine when I run the scene in Godot on the desktop, but it does not work when I run it on Android, and it also does not work when I set emulate_touchscreen on, on the desktop.
Below is the code for _input:
func _input(event):
if event.type == 6 or event.type == 3: #InputEvent.SCREEN_TOUCH:
player_running = !player_running
if player_running:
player.play("run")
else:
player.play("idle")
You can make a big invisible/transparent TouchScreenButton and use the button action to not depend on input event methods (you can use Input.is_action_ once the button set the action).
Is a strategy used with any engine.
Thanks, I was actually doing this (using a sprite that covers the screen to catch presses), but I didn’t know what event to expect, and also I found out it was better to check on _process rather than _input.
mydoghasworms | 2016-10-30 12:59
One of the properties of TouchScreenButton, is called “action”, available on the inspector too, you can use a common action or set a unique one with no key binding and make the button fire that action and get it with Input.