+1 vote

Hey,

I would like to learn how to make mobile games. The game I'm working on is using swipe detection. After watching some tutorials I put together this code:

var swipe_start = null
var minimum_drag = 100

func _unhandled_input(event):
if event.is_action_pressed("click"):
    swipe_start = event.get_position()
if event.is_action_released("click"):
    _calculate_swipe(event.get_position())

func _calculate_swipe(swipe_end):
  if swipe_start == null: 
    return
  var swipe = swipe_end - swipe_start
  if abs(swipe.x) > minimum_drag:
    if swipe.x > 0:
        _right()
    else:
        _left()

This code should determine if the user swiped and in which direction (left or right). Also, in the Input Map I chose "click" to be left mouse click.

The game works when I'm playing on my laptop (I click and drag with mouse) so I published it on google play but when you play the game on phone the swipe detector doesn't work.

Any ideas

in Engine by (20 points)

1 Answer

0 votes

Try setting emualte mouse(or something like that) in the project settings.

beside, you can use _input(event) function and InputEventScreenTouch + InputEventScreenDrag to get swipes for your game(i used it and got some touch joysticks working and some nice things in my android game)

by (1,190 points)
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 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 webmaster@godotengine.org with your username.