mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Correct swipe fields
This commit is contained in:
parent
48aa2b3d71
commit
8f2faa7156
@ -3,6 +3,11 @@
|
|||||||
-- ended on one node
|
-- ended on one node
|
||||||
-- @module druid.swipe
|
-- @module druid.swipe
|
||||||
|
|
||||||
|
--- Components fields
|
||||||
|
-- @table Fields
|
||||||
|
-- @tparam node node Swipe node
|
||||||
|
-- @tparam[opt] node click_zone Restriction zone
|
||||||
|
|
||||||
--- Component events
|
--- Component events
|
||||||
-- @table Events
|
-- @table Events
|
||||||
-- @tfield druid_event on_swipe Trigger on swipe event
|
-- @tfield druid_event on_swipe Trigger on swipe event
|
||||||
@ -23,8 +28,8 @@ local M = component.create("swipe", { const.ON_INPUT })
|
|||||||
|
|
||||||
local function start_swipe(self, action)
|
local function start_swipe(self, action)
|
||||||
self._swipe_start_time = socket.gettime()
|
self._swipe_start_time = socket.gettime()
|
||||||
self.start_pos.x = action.x
|
self._start_pos.x = action.x
|
||||||
self.start_pos.y = action.y
|
self._start_pos.y = action.y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -34,9 +39,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function check_swipe(self, action)
|
local function check_swipe(self, action)
|
||||||
local dx = action.x - self.start_pos.x
|
local dx = action.x - self._start_pos.x
|
||||||
local dy = action.y - self.start_pos.y
|
local dy = action.y - self._start_pos.y
|
||||||
local dist = helper.distance(self.start_pos.x, self.start_pos.y, action.x, action.y)
|
local dist = helper.distance(self._start_pos.x, self._start_pos.y, action.x, action.y)
|
||||||
local delta_time = socket.gettime() - self._swipe_start_time
|
local delta_time = socket.gettime() - self._swipe_start_time
|
||||||
local is_swipe = self.style.SWIPE_THRESHOLD <= dist and delta_time <= self.style.SWIPE_TIME
|
local is_swipe = self.style.SWIPE_THRESHOLD <= dist and delta_time <= self.style.SWIPE_TIME
|
||||||
|
|
||||||
@ -72,7 +77,7 @@ function M.init(self, node, on_swipe_callback)
|
|||||||
self.node = self:get_node(node)
|
self.node = self:get_node(node)
|
||||||
|
|
||||||
self._swipe_start_time = false
|
self._swipe_start_time = false
|
||||||
self.start_pos = vmath.vector3(0)
|
self._start_pos = vmath.vector3(0)
|
||||||
|
|
||||||
self.click_zone = nil
|
self.click_zone = nil
|
||||||
self.on_swipe = Event(on_swipe_callback)
|
self.on_swipe = Event(on_swipe_callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user