0 votes

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:
in Engine by (117 points)

2 Answers

+1 vote
Best answer

OK, so from looking at examples, I eventually figured out that I need to process this in _process(event), and now I have the following, which works:

func _process(delta):
  player_running = Input.is_mouse_button_pressed(BUTTON_LEFT)

It's just not intuitive that on a mobile, the input for primary mouse button is treated the same as touch, but I'm glad that's sorted!

by (117 points)
0 votes

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.

by (7,934 points)

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.

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.


Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.