Topic was automatically imported from the old Question2Answer platform.
Asked By
morningkingdom
Hi, there.
I wanna hold the touch and while holding it, instance some sprites continuously.
I can handle the instance part, but dont now how the hold part.
i did try few things like
var touch_position
func _input(event):
if not event is Inputeventscreentouch:
return
if event.pressed:
touch_position = event.position
this is only return the value one time. i need it the update at it every frame so i need the use func _process function, but how can i reach the touch_position variable from _process function ?
You could probably just update a variable whenever the touch is changes, then in a _process function, do whatever you need to with the current position and touch state
var touch_position = Vector2()
func _input(event):
if not event is InputEventScreenTouch:
return
if event.pressed:
touch_position = event.position
else:
touch_position = Vector2()
func _process(_delta):
if touch_position:
sprite.instance()
or
func _input(event):
if not event is InputEventScreenTouch:
return
if event.pressed:
Input.action_press("hold")
else:
Input.action_release("hold")
func _process(delta):
if Input.is_action_pressed("hold"):
sprite.instance()
thank you for anwser but it still not work, i did it like this
extends Node2D
var touch_position = Vector2()
onready var sprite_test = preload("res://sahneler/skill_swipe_h.tscn")
func _input(event):
if not event is InputEventScreenTouch:
return
if event.pressed:
touch_position = event.position
else:
touch_position = Vector2()
func _process(delta):
if touch_position:
print (touch_position)
var sprite_instance = sprite_test.instance()
add_child(sprite_instance)
sprite_instance.position = touch_position
when i hold the press of screen touch, and swipe the finger, i need the new position of the touch in every frame, because of that we did use _process funtion, but it still only return the first coordinats of th touch value. i need it update at every frame. so that it will looks like a drawing a gesture.
Solve it. Well there are other problems pup-up but, lets face them an another day
this is the script:
its on the draw(Node2d) node:
extends Node2D
var touch_position = Vector2()
var current_touch = Vector2()
var sprite_instance
onready var sprite_test = preload("res://sahneler/skill_swipe_h.tscn")
func _input(event):
if event is InputEventScreenTouch and event.is_pressed():
touch_position = event.get_position()
if event is InputEventScreenDrag:
current_touch = event.get_position()
if event is InputEventScreenDrag and not event.is_pressed():
yield(get_tree().create_timer(0.25),"timeout")
current_touch = null
func _process(delta):
if current_touch:
print (current_touch)
sprite_instance = sprite_test.instance()
add_child(sprite_instance)
sprite_instance.position = current_touch
this is for delete the intanced sprites with timer: