0% found this document useful (0 votes)
6 views1 page

Touch and Drag Sprite Control Script

Uploaded by

haloofbuta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Touch and Drag Sprite Control Script

Uploaded by

haloofbuta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

extends Control

var dragging = false


var offset = Vector2()
var sprite
var touches = []

func _ready():
sprite = $Sprite

func _input(event):
if event is InputEventScreenTouch:
if [Link]:
[Link](event)
if len(touches) == 1:
dragging = true
offset = sprite.global_position - [Link]
elif len(touches) == 2:
var distance = touches[0].position.distance_to(touches[1].position)
[Link] = Vector2(1, 1)
[Link] *= distance / 100
else:
[Link](event)
if len(touches) == 0:
dragging = false
elif event is InputEventScreenDrag and dragging:
sprite.global_position = [Link] + offset
elif event is InputEventScreenDrag and len(touches) == 2:
var distance = touches[0].position.distance_to(touches[1].position)
[Link] = Vector2(1, 1)
[Link] *= distance / 100
extends

You might also like