This project has moved. For the latest updates, please go here.

Positioning of a randomly generated polygon from texture

Topics: Developer Forum
Nov 10, 2011 at 7:45 AM

Hi all,

I have a polygon created from a randomly generated texture (I used the texture to polygon example). The polygon is always the same width (768 pixels) but the maximum height is random and will change when the program is started. The shape of the polygon is different as well although the sides are always straight and the bottom is always flat (basically it's a randomly generated terrain). I can generate the polygon from the texture fine and it works lovely, collision detection works and all is well. The problem I have is getting the sprite to line up with the physics mesh. Or more correctly, to get the mesh to stay in the one spot. I think it's due to the shape having a different centroid everytime, but I can't get it to render in the same spot. The position is always set at 0,0 but the shape is never there. It changes its place everytime I run the program. What I would like to be able to do is anchor the shape on one of the bottom corners since those will be the same everytime, instead of using the centroid to anchor as it changes with every random shape. The terrain will change during play as well so I can't just manually move it as it will be regenerated.

Anyone have any ideas on how I can do this?

Thanks in advance.

Nov 10, 2011 at 11:46 AM

i think LocalCenter will do it (idk if this is the right name because i have no code on this pc at the moment)

Nov 10, 2011 at 1:19 PM

Ah... I'm an idiot... The answer was right in front of me. From the example (which was part of my code already):

 //2. To draw the texture the correct place.
 _origin = -centroid;

*Sigh* Just put that in the the draw call for the origin and it works like a charm.. Can't believe I missed it >.<

Thanks for you response.