Last active
August 29, 2015 13:58
-
-
Save Lerg/10001608 to your computer and use it in GitHub Desktop.
Enter Frame functions manager with tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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