如何将表添加为 EventListener?我正在开发一个作为 hello-world 项目的突破游戏,我想添加“双球”的效果。所以基本上我想添加球balls table
然后检查其中一个球是否击中砖块
我的代码适用于
balls["ball"]:addEventListener( "collision", removeBricks )
但如果我尝试以下操作:
balls:addEventListener( "collision", removeBricks )
我越来越Runtime error ...\main.lua:753: attempt to call method 'addEventListener' (a nil value)
stack traceback:
我试过的:
local balls = {}
balls["ball"] = crackSheet:grabSprite("ball_normal.png", true)
balls["ball"].name = "ball"
function removeBricks(event)
if event.other.isBrick == 1 then
remove brick...
end
end
balls.collision = removeBricks
balls:addEventListener( "collision", removeBricks )