Best Way to Create 'Infinite Ground'?
Posted: Fri Dec 13, 2013 4:33 am
I have a sort of side-scrolling game in which a hero moves from left to right over a ground that I'd like to be dynamically generated and infinite.
To accomplish this, I have 2 large sensors that are off screen and follow the hero - one in back (to the left) and one in front (to the right). Right now the idea is to create a chain shape for the ground and use SetNextVertex to create the next parts of the ground when the hero moves. When the front sensor is not touching any part of the track, I'll create a new vertex on the chain so there is always ground for the hero to traverse on.
The problem is with the back sensor and destroying vertices in order to conserve memory. Ideally I'd like to destroy/remove a vertex from the chain once it hits the back sensor, but I can't find any way to do this. Is the only option here to destroy the whole chain shape and create a new one with each step? I also considered using individual edge shapes so that each new part of the ground is its own body, but then I read in the box2d manual that there are certain issues with "ghost" collisions with internal vertices when its done this way.
I'm sure this is a pretty common setup for games - what do you recommend is the best way to go about creating this infinite ground?
To accomplish this, I have 2 large sensors that are off screen and follow the hero - one in back (to the left) and one in front (to the right). Right now the idea is to create a chain shape for the ground and use SetNextVertex to create the next parts of the ground when the hero moves. When the front sensor is not touching any part of the track, I'll create a new vertex on the chain so there is always ground for the hero to traverse on.
The problem is with the back sensor and destroying vertices in order to conserve memory. Ideally I'd like to destroy/remove a vertex from the chain once it hits the back sensor, but I can't find any way to do this. Is the only option here to destroy the whole chain shape and create a new one with each step? I also considered using individual edge shapes so that each new part of the ground is its own body, but then I read in the box2d manual that there are certain issues with "ghost" collisions with internal vertices when its done this way.
I'm sure this is a pretty common setup for games - what do you recommend is the best way to go about creating this infinite ground?