如何更新或操作嵌套在多个组中的精灵?
我首先尝试使用精灵将“enterFrame”事件直接添加到所需的类(没有成功)
我的代码
local box = {}
-- PUBLIC FUNCTIONS
function box:new( )
local group = display.newGroup()
local image = display.newImage("crate.png")
group:insert(image)
function group:update()
image.rotation = image.rotation + 1
end
return group
end
return box
其次,我想添加一个
Runtime:addEventListener("enterFrame", enterFrame)
在我的场景中,然后遍历添加到场景中的组 ( scene.view
) 并在那里调用自定义更新函数,将更新向前发送,直到它到达我的班级。但是我还没有找到检查组是否有更新方法的方法。现在我只是调用更新,即使该组没有它。
function enterFrame (event)
local group = scene.view
for i=1,group.numChildren do
group[i]:update()
end
end