Skip to content

Instantly share code, notes, and snippets.

@Lerg
Last active August 29, 2015 13:58
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 Lerg/10001608 to your computer and use it in GitHub Desktop.
Save Lerg/10001608 to your computer and use it in GitHub Desktop.
Enter Frame functions manager with tags
local _M = {}
function _M.nextFrame(f)
timer.performWithDelay(1, f)
end
function _M.enterFrame()
for i = 1, #_M.enterFrameFunctions do
_M.enterFrameFunctions[i][1]()
end
end
function _M.eachFrame(f, tag)
if not _M.enterFrameFunctions then
_M.enterFrameFunctions = {}
Runtime:addEventListener('enterFrame', _M.enterFrame)
end
table.insert(_M.enterFrameFunctions, {f, tag})
return f
end
function _M.eachFrameRemove(f)
if not f or not _M.enterFrameFunctions then return end
local ind
for i = 1, #_M.enterFrameFunctions do
if _M.enterFrameFunctions[i][1] == f then
ind = i
break
end
end
if ind then
table.remove(_M.enterFrameFunctions, ind)
if #_M.enterFrameFunctions == 0 then
Runtime:removeEventListener('enterFrame', _M.enterFrame)
_M.enterFrameFunctions = nil
end
end
end
function _M.printEnterFrameFunctions()
if not _M.enterFrameFunctions then return end
for i = 1, #_M.enterFrameFunctions do
print('f =', _M.enterFrameFunctions[i][1], 'tag =', _M.enterFrameFunctions[i][2])
end
end
return _M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment