How to check if a display object is in view?

I would like to do some serious memory optimising for our game, and to do that I have written an algorithm that hides wall tiles, when they are not in view.

It’s something like this (pseudo code):
[lua]w, h = display.contentWidth, display.contentHeight

topLeft = 0, 0
topRight = w, 0
bottomRight = w, h
bottomLeft = 0, h

for i, t in wallTiles
if t.x < topLeft.x and t.y < topLeft Y or t.x > topRight.x and t.y < topRight.y [… etc …] then
t.isVisible = false
end
end[/lua]

This has improved performance on bigger levels a lot, but I am trying to extend this functionality to animations, timers and so on.

Is there any way to just get a table of all the display objects in view? Something like:
[lua]tableOfObjects = display.objectsInView ()[/lua]

Or is there another smart way of doing in-view rendering that I am missing?

Thanks in advance :slight_smile: [import]uid: 117153 topic_id: 24998 reply_id: 324998[/import]