how to detects objects going offscreen (to then remove for memory management)

I have some physics objects that get created and fall under gravity, then fall off-the-screen.

How can I set something up to auto-detect items as they fall offscreen so then I can issue an myObject.remove, for memory management?

[import]uid: 140210 topic_id: 25108 reply_id: 325108[/import]

You could have something that they collide with off screen. The collision event for that object would remove any objects that collide with it. [import]uid: 103624 topic_id: 25108 reply_id: 101989[/import]

good point - there’s no built in “wentOffScreen” event hidden away somewhere then? [import]uid: 140210 topic_id: 25108 reply_id: 101996[/import]

Normal way to handle this is with something like IKinx suggested, although if you look at MultiPuck sample code there is an example for checking items off screen and removing them.

But no, no simple “wentOffScreen” event, sorry :wink: [import]uid: 52491 topic_id: 25108 reply_id: 102011[/import]

ok thanks [import]uid: 140210 topic_id: 25108 reply_id: 102012[/import]

A potentially “safer” approach is to place an invisible sensor that covers the entire screen. Then use the “ended” phase in its collision listener. That way, objects that travel off the screen in any direction (left, up, down, whatever) will register that they exited the screen and you can remove them. Another slight advantage is that if you have small objects and giant objects, like big vs. small asteroids in the classic game, you don’t need to worry about the bigger objects being “prematurely deleted” if part of them in still on screen when they hit some arbitrary boundary line off the screen.

Brent [import]uid: 9747 topic_id: 25108 reply_id: 102034[/import]