Corona performance with too many physics bodies

I’m designing a maze in Corona and have a question about performance of Corona with too many physics bodies being displayed. My mazes will have 200 - 300 physics bodies, which will include board squares, keys  & coins, border lines between board squares, and other obstacles.

What will this do to Corona’s speed performance during game play? Will Corona slow to a crawl, or be playable?

Any comments or suggestions?

Hi @gmolatore,

200-300 physics bodies will probably cause performance issues. If you’re designing a maze game, can’t you combine multiple “square obstacles” into larger physics bodies? For example, if there’s a wall which is 1 tile wide by 10 tiles tall, consider creating one large physics body for the entire wall, thus making 1 physics body instead of 10 physics bodies.

Hope this helps,

Brent

Thanks Brent!

If objects are set to display on screen, but physics are turned off until needed on each object, does that reduce memory use? I’m still learning corona, but would something like isActive = false work to reduce memory requirements of objects not currently being used? Also wondering if objects in display groups are more efficient than individual objects.

Hi @gmolatore,

Yes, you could deactivate physics bodies that are off-screen and that would likely improve performance, but ideally you should minimize the total amount and combine bodies when possible.

Brent

Are vector graphics “counted” for memory the same as other physics bodies? Do vector bodies affect memory differently than scaled images?

Yes, vector objects “count” the same as image-based physics bodies, but they won’t penalize you toward texture memory, which is a little different than overall memory. See this guide:

https://docs.coronalabs.com/guide/basics/optimization/index.html

Also, you should definitely be aware of some physics “limitations” before you proceed:

https://docs.coronalabs.com/guide/physics/limitations/index.html

Brent

Hi @gmolatore,

I’m working on an app with a crazy number of physics bodies (sometimes 700 - 800) with hundreds of joints as well.  I’ve found that collision filters are the way to go.

A few months ago, I started adding shading (normal maps via Sprite Illuminator) and saw my performance start to drop.  I spent some time reallocating my collision filters and achieved a great performance boost.

I played around with the isActive setting as well and, for my app, it wasn’t an appropriate solution but I can’t remember why.

Jonathan

Thanks Jonathan!

Where can I learn about collision filters?

What’s the basic concept of collision filters?

Gary

You are welcome Gary,

Basically, it means that you can choose to have some physics objects ignore collisions with other objects.  That can cut down on your bandwidth quite a bit.  Take a look at the chart at the end of the tutorial in the link below.  It makes it all very clear.

https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html#filtering

Jonathan

Hi @gmolatore,

200-300 physics bodies will probably cause performance issues. If you’re designing a maze game, can’t you combine multiple “square obstacles” into larger physics bodies? For example, if there’s a wall which is 1 tile wide by 10 tiles tall, consider creating one large physics body for the entire wall, thus making 1 physics body instead of 10 physics bodies.

Hope this helps,

Brent

Thanks Brent!

If objects are set to display on screen, but physics are turned off until needed on each object, does that reduce memory use? I’m still learning corona, but would something like isActive = false work to reduce memory requirements of objects not currently being used? Also wondering if objects in display groups are more efficient than individual objects.

Hi @gmolatore,

Yes, you could deactivate physics bodies that are off-screen and that would likely improve performance, but ideally you should minimize the total amount and combine bodies when possible.

Brent

Are vector graphics “counted” for memory the same as other physics bodies? Do vector bodies affect memory differently than scaled images?

Yes, vector objects “count” the same as image-based physics bodies, but they won’t penalize you toward texture memory, which is a little different than overall memory. See this guide:

https://docs.coronalabs.com/guide/basics/optimization/index.html

Also, you should definitely be aware of some physics “limitations” before you proceed:

https://docs.coronalabs.com/guide/physics/limitations/index.html

Brent

Hi @gmolatore,

I’m working on an app with a crazy number of physics bodies (sometimes 700 - 800) with hundreds of joints as well.  I’ve found that collision filters are the way to go.

A few months ago, I started adding shading (normal maps via Sprite Illuminator) and saw my performance start to drop.  I spent some time reallocating my collision filters and achieved a great performance boost.

I played around with the isActive setting as well and, for my app, it wasn’t an appropriate solution but I can’t remember why.

Jonathan

Thanks Jonathan!

Where can I learn about collision filters?

What’s the basic concept of collision filters?

Gary

You are welcome Gary,

Basically, it means that you can choose to have some physics objects ignore collisions with other objects.  That can cut down on your bandwidth quite a bit.  Take a look at the chart at the end of the tutorial in the link below.  It makes it all very clear.

https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html#filtering

Jonathan