Hey there !
I’m trying to optimize the physics performance of my game. It works fine on iOS (it could be better though), but on Android… well… it does not.
Just so you know : my game is not a tile based game. I have a lot of physics bodies (~ 300…) but I’d say that most of them (around 80%) are just static bodies. There are around a hundred of physic bodies in each level (of course, it depends on each level).
So, I tried to deactivate all the physical bodies that are offscreen by setting “isBodyActive” as false.
Today, I’ve done something like that :
-
I create an array where I’ve listed all the physical bodies
-
In an enterFrame listener, I read the array and see if the coordinates are off or on screen.
It does work (bodyActive is set to false), but it doesn’t seem to change anything : my game is still slow. My guess is having an enterFrame listener checking all the bodies one by one is just… too much to handle.
So, to avoid having an enterFrame listener and getting x and y, I was thinking about doing this :
-
One rectangular box, corresponding to the “on screen” zone, set as a physical body, then set as a sensor.
-
Adding a collision listener to that box : everytime it touches any other body, the body is activated, otherwise it’s deactivated.
So here are my questions :
- Is using “isBodyActive” effectively efficiant ?
- Is there any better way to deal with offscreen physical bodies ?
BONUS QUESTION : What is better ? Using several different physical bodies, or instead, using one multi-element physic body ?
