4
\$\begingroup\$

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?

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

1 Answer 1

0
\$\begingroup\$

I would suggest changing position of already created chunks.

For example:

if(exampleChunk.getX()-exampleChunk.getWidth()<0){  
    exampleChunk.setX(Gdx.graphics.getWidth());
}else{
    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.

\$\endgroup\$
1
  • \$\begingroup\$ I was thinking of doing this before but I didn't want to create more than 5 chunks, haha my bad. \$\endgroup\$ Commented Jan 7, 2016 at 17:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.