How you make gui node move toward another gui node?
If you look video, green spawned node must move toward green node on topright corner. Position are somehow wrong.
script used:
function init(self)
msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local screen = vmath.vector3(action.x, action.y, 0)
local prefab = gui.get_node("prefab")
local clone = gui.clone(prefab)
gui.set_enabled(clone, true)
gui.set_position(clone, screen)
local target_position = gui.get_screen_position(gui.get_node("icon"))
gui.animate(clone, "position", target_position, gui.EASING_LINEAR, 0.5, 0, function()
gui.delete_node(clone)
end)
end
end
Is there gui animate screen position? because if you try place at exact position that works.
You could create an empty node with the same parent as the clone, use gui.set_screen_position() to set its position to the target, then get the empty node’s new position with gui.get_position(), and use that target position for gui.animate().
function init(self)
msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local screen = vmath.vector3(action.x, action.y, 0)
local prefab = gui.get_node("prefab")
local clone = gui.clone(prefab)
gui.set_enabled(clone, true)
gui.set_position(clone, screen)
-- parenting
local panel = gui.get_node("panel")
gui.set_parent(clone, panel, true)
local target_position = gui.get_position(gui.get_node("icon"))
gui.animate(clone, "position", target_position, gui.EASING_LINEAR, 0.5, 0, function()
gui.delete_node(clone)
end)
end
end