What happen when object fall into non visible area?

Hi,

I am creating a game, with physic object falling down from top to bottom.

There is no boundary, so the object can fall out of view.

However, I experience lag and drop in framerate after the falling objects increased.

Do I need to manually removeSelf() every object? Or Corona will handle it?

Thanks. [import]uid: 138320 topic_id: 24743 reply_id: 324743[/import]

You need to manually do something about it; objects off screen still exist.

The MultiPuck demo in SampleCode shows a good example of how to do this; CoronaSDK > SampleCode > Physics > MultiPuck

Or you could draw a platform outside the screen that removed the objects when they collided with it.

Peach :slight_smile: [import]uid: 52491 topic_id: 24743 reply_id: 100274[/import]

You can do this with off screen boundaries.

Set up a display.newRect about 50 to 100 pixels out of screen on the bottom. Attach a listener to it and write a function that does a display.remove (object) << my first choice or a removeSelf() <Corona won’t handle anything like this unless you TELL IT to. You will find out that this is the case with a LOT of things with corona.

If you need sample code, I could cook something up quick but this should be pretty basic to do :slight_smile:
ng [import]uid: 61600 topic_id: 24743 reply_id: 100371[/import]

I wrote my first game in late 1984 using AppleSoft BASIC. A couple years later I was writing commercial games in 65C02/65C816 assembly language.

I am NOT a newbie.

But apparently I’m not used to the EASE you young whippersnappers have in how you do things these days – set up a block below the screen and watch for a collision?!

Awesome idea!

In Roly-Polies HD I needed to watch for the RP (Roly-Poly, of course) to drop off the screen and I used a different system – set up a timer for that RP which checked every 150 ms to see whether he was off the screen or not.

To be fair, I also needed to check to see whether he was still moving (he can get stuck in some places and then must self-destruct) so I couldn’t use the “block below the screen” method, but it’s still a cool way to do it. (I also needed to record the path of the RP which is why I checked every 150ms instead of a longer period of time.)

In case someone wants to know at least one way that an old geezer might do it, here’s the pertinent code:

[lua]PeaStandard = display.newImage(“images/Pea-Standard.png”)
PeaStandard.x = event.x
PeaStandard.y = 30
physics.addBody(PeaStandard,“dynamic”, {density=1, bounce=.1, friction = 1, radius = 18})

local function isPeaMoving()
– see if it’s offscreen, if so, just delete it.
if PeaStandard.x < -20 or PeaStandard.x > 1024 or PeaStandard.y < -10 or PeaStandard.y > 768 then
timer.cancel ( PeaStandard.tmr )
display.remove(PeaStandard)
return
end
– other code here to record path and see if RP was still moving
end

PeaStandard.tmr = timer.performWithDelay(150, isPeaMoving, 0)[/lua]

Just remember if you do something like this to cancel the timer before you destroy the object. Bad things happen if you don’t do that.

Also, a “real programmer” wouldn’t hard code the values for the edges of the screen. *ahem* Use variables, kids, they’re your friends.

Jay
[import]uid: 9440 topic_id: 24743 reply_id: 103822[/import]