I'm currently working on a 2D platforming game with an infinite map.

I did my research and I discovered that I can use chunks. Based on my understanding chunks is about spawning terrain at the right time and then removing them when not needed.

My idea was to pool a body then add it to an array list so that I can use a static body and remove it any time without any problems.

But then I realized that Pooling is not applicable to bodies.

How can I spawn chunks, without creating a new body every single time and then remove it when not needed?

  • 1
    \$\begingroup\$ Have you found an actual performance problem? Are you sure creating/disposing of chunks as needed isn't a fine solution? \$\endgroup\$ – Richard Tingle Jan 7 '16 at 22:00

I would suggest changing position of already created chunks.

For example:

    exampleChunk.setX(exampleChunk.getX()-(200*delta);  //delta being the render(float delta) value.

Simply use this code for every chunk every time you update the state of your game.

I find it pretty easy, and you won´t need to dispose or create any chunks.

Hope it helps, tell me if you have any question.

EDIT: This is just an example, you can also update Y value, or whatever changes you want to make, I think it is simple enough to understand it, even with my poor english.

| improve this answer | |
  • \$\begingroup\$ I was thinking of doing this before but I didn't want to create more than 5 chunks, haha my bad. \$\endgroup\$ – masterYao09 Jan 7 '16 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.