Box2D is a large number of static objects



  • I'm working on a secret-based player. Below, I will bring key milestones during implementation to facilitate understanding of the problem.

    There is a mass in the form of world[x][y], which determines the size of our world. This mass is filled with figures that correspond to different temples.

    Tiles are squares of the same size on W and H.

    After that, I'm putting all the time on the monitor, respectively, by the side of the card scrulling function and the sequestration function that does not fall into the very visible part of the annex, i.e., "I don't see what I can't see."

    Everything's fine at this stage, working properly, any size of the world doesn't give rise to FPS.

    It's time to add characters. For certain reasons, a ready physical movement (Box2D) has been chosen to test conflicts.

    Great. I am building a body mass (under this notion in this context, I merged b2Body, b2BodyDef, b2PolygonShape) in the form of [x][y], followed by the rounding up again, but this time we are setting out the coordinates and dimensions of the bodies.

    In the drawing cycle, the body coordinates are obtained and the secrets are drawn from them. It works.

    But now we're changing the size of the world, and we're finally getting a... FPS board! And the more the world size, the more the FPS falls. I understand this has to do with a large number of static objects and I have no idea how to optimize this moment. DoSleep is very small.

    What can I do? Maybe I'm doing something wrong?



  • What are the static objects?

    As I understand, you've got all the characters active and processed. Total in each iteration The game cycle, which is probably why the FPS is running. Dynamic objects are usually processed in such platforms only those that enter an active part of the map. Or even created when they get into the active part of the map, then they're removed.

    Try or set up or operate moving objects dynamically. Or treat only visible objects in the game cycle.

    In the second case, there is still a need to choose the type of collection that is needed to make rapid access only to visible objects and to quickly compute/change the " Visibility " parameter.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2