Skip to content

Instantly share code, notes, and snippets.

@litefeel
Last active April 11, 2016 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litefeel/b48f5d832968714de9ce315f3f744e55 to your computer and use it in GitHub Desktop.
Save litefeel/b48f5d832968714de9ce315f3f744e55 to your computer and use it in GitHub Desktop.
lua分帧处理任务,多用于显示对象创建
local FrameTaskExt = {}
FrameTaskExt.__index = FrameTaskExt
-- isFinish, isContinue function taskFunc(times)
function FrameTaskExt.new(taskFunc)
local o = {}
setmetatable(o, FrameTaskExt)
o:_init(taskFunc)
return o
end
function FrameTaskExt:start()
if not self._isRuning and not self._isFinish then
self._timer:Start()
end
end
function FrameTaskExt:stop()
if self._isRuning then
self._timer:Stop()
end
end
function FrameTaskExt:reset(taskFunc)
self._taskFunc = taskFunc or self._taskFunc
self._times = 0
self._isFinish = false
self:stop()
end
function FrameTaskExt:_init(taskFunc)
self._taskFunc = taskFunc
self._times = 0
self._isRuning = false
self._isFinish = false
self._timer = FrameTimer.New(function() self:_onTimer() end, 1, -1)
end
function FrameTaskExt:_onTimer()
self._times = self._times + 1
local isContinue = false
self._isFinish, isContinue = self._taskFunc(self._times)
if self._isFinish then
isContinue = false
self._isFinish = true
end
if isContinue then
self:_onTimer()
end
end
return FrameTaskExt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment