mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Add general swipe and drag examples
This commit is contained in:
46
example/examples/general/drag/drag.gui_script
Normal file
46
example/examples/general/drag/drag.gui_script
Normal file
@@ -0,0 +1,46 @@
|
||||
local druid = require("druid.druid")
|
||||
|
||||
|
||||
local function on_drag_callback(self, dx, dy)
|
||||
self.position.x = self.position.x + dx
|
||||
self.position.y = self.position.y + dy
|
||||
gui.set_position(self.box, self.position)
|
||||
end
|
||||
|
||||
|
||||
local function on_drag_end(self)
|
||||
self.position.x = 0
|
||||
self.position.y = 170
|
||||
gui.animate(self.box, "position", self.position, gui.EASING_OUTSINE, 0.3)
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
self.box = gui.get_node("icon_box")
|
||||
self.position = gui.get_position(self.box)
|
||||
self.drag = self.druid:new_drag("drag_node", on_drag_callback)
|
||||
|
||||
self.drag.on_drag_end:subscribe(on_drag_end, self)
|
||||
end
|
||||
|
||||
|
||||
function final(self)
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
self.druid:update(dt)
|
||||
end
|
||||
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
self.druid:on_message(message_id, message, sender)
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
return self.druid:on_input(action_id, action)
|
||||
end
|
Reference in New Issue
Block a user