Corona "tick" issues - addEventListener
I've been trying to write out a custom tick using the Corona SDK (using Lua). The key seems to be these "eventListeners," but I'm also trying to get them to work with classes. right now i have this class "World" set up. I'm trying to add an EventListener to my "tick" function, but Corona is telling me I can't do it.
function World:tick()
--player:tick()
--camera:tick(player.x,player.y)
--for i=0,monsters.length do
-- monster[i]:tick()
if(rwalk) then
mainGroup.x = mainGroup.x-10
elseif(lwalk) then
mainGroup.x = mainGroup.x+10
end
end
Runtime:addEventListener("enterFrame",tick)
Error: Runtime error: assertion failed! stack traceback: [C]: ? [C]: in function 'assert' ?: in function 'getOrCreateTable' ?: in function 'addEventListener' ?: in function 'addEventListener' C:\Users\Evan\Desktop\lua\test game\main.lua:337:开发者_高级运维 in main chunk
This works for me. Should work for you:
World = {}
function World:tick()
print "Hello!"
end
display.setStatusBar(display.HiddenStatusBar)
Runtime:addEventListener("enterFrame", World.tick)
All you were missing was to specify the function using World.tick
instead of tick
.
精彩评论