I am working on a tile-based platform game. Below are the main steps at runtime to facilitate understanding of the problem.
There is an array in the form of world [x] [y], which determines the size of our world. This array is clogged with numbers that correspond to different tiles.
Tiles are squares of the same size in W and H.
After that, I bring all the tiles onto the monitor, respectively, next to it I screw the card scrolling function and the clipping function of what does not fall into the visible part of the application, i.e. "I do not draw what is not visible."
At this stage, everything is fine, it works as it should, any size of the world does not cause FPS drawdown.
It's time to add a character. For certain reasons, I decided to use a ready-made physics engine (Box2D) to check the collisions.
Fine. I create an array of bodies (under this concept in this context, I combined b2Body, b2BodyDef, b2PolygonShape) in the form [x] [y], after which we again run the array through the cycle, but this time we set the coordinates and dimensions of the bodies.
In the rendering cycle, we obtain the coordinates of the bodies and, on the basis of them, draw tiles. Everything is working.
But now we are changing the size of the world and as a result we get ... FPS drawdown! And the larger the size of the world, the stronger the FPS falls. As I understand it, this is due to the large number of static objects and I have no idea how exactly to optimize this moment. doSleep has a very small effect.
What can be done? Maybe I'm doing something wrong?