Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | melka24 |
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