Ooh, that sounds like a plan
Thanks.
However, I am currently using the physics engine to determine whether an object is in view or not ( I know, it sounds pretty heavy ). I can’t find any mention on how to do it in these forums or indeed any lua documentation I’ve come across.
Would I have to do something like:
[lua]local function checkView ()
for i, o in pairs ( allObjects ) do
– if “o” is in view
o.isVisible = true
– else
o.isVisible = false
end
end
Runtime : addEventListener ( “enterFrame”, checkView )[/lua]
Because I tried that earlier, and it took up even more memory. Is there something clever that I have overlooked?
EDIT:
All right, I tried that, and it actually seems to improve performance. I have a lot of display objects to deal with though, so it still gets laggy sometimes. I guess we’ll have to redo some levels to account for that.
Here’s the code, in case anyone wants to know:
[lua]checkObjects = function ()
local w = display.viewableContentWidth * 0.75
local h = display.viewableContentHeight * 0.75
local p = lvlGroup.player
local checkIt = function ( o )
if o.x < ( p.x + w ) and o.x > ( p.x - w ) and o.y < ( p.y + h ) and o.y > ( p.y - h ) then
o.isVisible = true
if o.animating == false and not o.objectType == “player” then
o : prepare ( o.sequence )
o : play ()
end
o.isBodyActive = true
else
o.isVisible = false
if o.animating then
o : pause ()
end
o.isBodyActive = false
end
end
local iterate = function ()
for i, o in pairs ( lvlGroup.tiles ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.items ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.env ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.npcs ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.doors ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.switches ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.overlays ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.propellers ) do
checkIt ( o )
end
for i, o in pairs ( lvlGroup.reversers ) do
checkIt ( o )
end
checkIt ( lvlGroup.goal )
end
iterate ()
end[/lua]
A timer is calling that function every 500 ms [import]uid: 117153 topic_id: 26135 reply_id: 105988[/import]