Physics Engine Docs - physics.removeBody() vs. display.remove()

Some clarity please.

It appears that if display.remove() is called on an object that was used as a physics body, the object is also removed from the physics engine. It is noted in the docs that calling physics.removeBody() on that object will not work if called during a collision event handling cycle. So what happens if the object is removed from the display via display.remove(object) or object.removeSelf()? Is this also going to fail? Is it bad practice to call “removeSelf()” on a physics object without calling “removeBody()” on it first?

Finally, it appears that this might be occurring when a physics object flies off the screen. Not sure yet. Is this true? It’s possible to test all of this stuff, case by case, but why put every developer through that when a note in the docs could save that time? And some of these details could have hidden negative side effects that don’t show up in simple case-tests… knowing the details of what the desired method functionality is can also help avoid bug reports for things that aren’t bugs-- hey, that would save Corona’s team time as well as us developers!..

Look, I know you Corona guys are working hard to give us this cool tool, but it would be great to have these kind of details in the documentation.

[import]uid: 10818 topic_id: 30176 reply_id: 330176[/import]

Hi duneunit, hopefully I can clarify this for you.

“physics:removeBody()” is not often needed. You certainly do NOT need to call it every time before you remove an object from the screen using “removeSelf()”. The “removeBody()” function was added for those users who need to remove a physics body without actually removing the image object… or for those who need to remove a physics body of one shape/size and replace it with another (because you can’t “morph” an existing body).

It’s fairly straightforward to see if Corona is freaking out if you try to perform some physics action upon collision (in the same cycle). Just check the terminal: it usually warns you. I wish there was a defined set of rules, but some things can be executed directly on collision, others can’t. It’s just trial and error, sorry to say. Removing a body on collision should NOT be one of these warnings… I never need to set a short delay timer to remove colliding bodies. In fact, most actions seem to be allowed… just a couple exceptions comes to mind, one being “isBodyActive” which always cries foul.

Physics bodies are not removed when they fly off the screen, you need to handle that. Corona’s image culling only ensures that graphical aspects are not processed by the OpenGL renderer when they reside off the screen. The physics engine is under no such restrictions.

Hope this helps!
Brent
[import]uid: 9747 topic_id: 30176 reply_id: 120817[/import]

@Brent: Thanks for the input! I wish the docs would include the extra details you gave, but at least people like you give quick answers on the Forums! :slight_smile:

[import]uid: 10818 topic_id: 30176 reply_id: 121187[/import]

Hi duneunit, hopefully I can clarify this for you.

“physics:removeBody()” is not often needed. You certainly do NOT need to call it every time before you remove an object from the screen using “removeSelf()”. The “removeBody()” function was added for those users who need to remove a physics body without actually removing the image object… or for those who need to remove a physics body of one shape/size and replace it with another (because you can’t “morph” an existing body).

It’s fairly straightforward to see if Corona is freaking out if you try to perform some physics action upon collision (in the same cycle). Just check the terminal: it usually warns you. I wish there was a defined set of rules, but some things can be executed directly on collision, others can’t. It’s just trial and error, sorry to say. Removing a body on collision should NOT be one of these warnings… I never need to set a short delay timer to remove colliding bodies. In fact, most actions seem to be allowed… just a couple exceptions comes to mind, one being “isBodyActive” which always cries foul.

Physics bodies are not removed when they fly off the screen, you need to handle that. Corona’s image culling only ensures that graphical aspects are not processed by the OpenGL renderer when they reside off the screen. The physics engine is under no such restrictions.

Hope this helps!
Brent
[import]uid: 9747 topic_id: 30176 reply_id: 120817[/import]

@Brent: Thanks for the input! I wish the docs would include the extra details you gave, but at least people like you give quick answers on the Forums! :slight_smile:

[import]uid: 10818 topic_id: 30176 reply_id: 121187[/import]