When adding a 'layer' to a scene like this:
local layer = Sprite.new();
self:addChild(layer); |
How do you then get the layer child included in the onEnterFrame loop that updates all the physic bodies and sprites:
local function onEnterFrame()
-- edit the step values if required. These are good defaults!
self.world:step(1/60, 8, 3)
for i = 1, self:getNumChildren() do
local sprite = self:getChildAt(i)
if sprite.body then
local body = sprite.body
local bodyX, bodyY = body:getPosition()
sprite:setPosition(bodyX, bodyY)
sprite:setRotation(body:getAngle() * 180 / math.pi)
end
end
end |
Would you create a separate loop for each layer?
Thanks
Comments
Or else you would simply waste your valuable resources looping through objects on multiple dimensions or through objects, that does not have box2d bodies attached.
Look at http://www.giderosmobile.com/forum/discussion/1780/extending-gideros#Item_1 implementation of box2d wrapper for updating objects