Moving a Polygon based on Camera position

I am in the process of implementing TMX Maps (made in Tiled) for my game. In Tiled, I can create polygons, which leaves a tag, containing the points.

Loading in these points to a Polygon (java.awt.Polygon) isn’t a problem. When all points are loaded into a Polygon (which also had an x and y position, which is the origin of the Polygon), and I draw it, it looks perfect.

However, when I was to move it the troubles started. Every tick, I want to set the position of this Polygon according to the x, y position (the origin), and the Camera position, so that when I draw it, it will draw on position.x – Camera.x and position.y – Camera.y. So every tick, I want to set the (x, y) position of the Polygon equal to position – Camera.position.

I thought that this would be as simple as calling the translate(position.x – Camera.x, position.y – Camera.y) function in the polygon every tick, but the problem here is that this function adds a delta, instead of setting the position. Because of this, the Polygon won’t stay still when the Camera is still, because it adds this delta, so the Polygon just moves off the screen.

So, the question is really how to set the position of a polygon every tick, instead of adding a delta to it every tick?

Leave a Reply

Your email address will not be published. Required fields are marked *