Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Syl |
Greets!
How to do that please?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Syl |
Greets!
How to do that please?
Reply From: | Bartosz |
on mouse click check if cursor is inside of sprite
mark sprite as dragged e.g. node_responsible_for_draggin.dragged = sprite
in _process
method set sprites global position to mouse global position sprite.global_position = get_global_mouse_position())
on mouse release unmarked dragged sprite
Update
to move sprite toward mouse click you can use tween and global_mouse_position()
simple script:
extends Node2D
func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
$Tween.interpolate_property($sprite, "global_position",$sprite.global_position, get_global_mouse_position(), 1,Tween.TRANS_LINEAR,Tween.EASE_IN)
$Tween.start()
here demo in my godot-recipes
project
Oops, fear that I’ll need more study of script, my actual knowledge bein limited to the copy/paste of some lines… Any tutos that I may check, usin that mouse movement?
Syl | 2018-03-25 19:43
I’m not aware about tutorial covering dragging sprites. here answer how to detect mouse clicking on sprite
Bartosz | 2018-03-25 20:12
Thxs, but I don’t want to click on sprite, juste movin the sprite toward the click.
Syl | 2018-03-25 20:28
then please update your question to reflect that and in the mean time I’ll prepare answer for you
Bartosz | 2018-03-25 20:41
Okokok. Done and edited.
Syl | 2018-03-25 20:50