- #1
JoAuSc
- 198
- 1
I'm trying to create a computer game (a platformer); currently I'm just trying to display a Polygon on the screen.
I have this class Charac, which contains a Polygon which defines its shape. If you display the bare Polygon, it'll put the shape at 0,0 on the screen. In order to move the Polygon to the right part of the screen, I have code which looks something like this:
Here's the problem: when I do the above, particle's Polygon gets translated too, rather than just poly2. This means every time I update the screen, the Polygon keeps moving in the (xPosition,yPosition) direction.
I remember reading a similar problem on these forums, and it involved clones or something. Can anyone give me a simple solution to translating poly2 while leaving particle.getPolygon() alone?
I have this class Charac, which contains a Polygon which defines its shape. If you display the bare Polygon, it'll put the shape at 0,0 on the screen. In order to move the Polygon to the right part of the screen, I have code which looks something like this:
Code:
public void updateGraphics() {
// ...
/* xPosition and yPosition are int variables which are where I want the
* Polygon to be displayed. particle is the name of the character/shape
* you move around the screen. drawPanel is this separate class which
* successfully displays whatever polygons you tell it to. */
Polygon poly2 = particle.getPolygon();
poly2.translate( xPosition, yPosition );
drawPanel.setPolygon( poly2 );
// ...
}
Here's the problem: when I do the above, particle's Polygon gets translated too, rather than just poly2. This means every time I update the screen, the Polygon keeps moving in the (xPosition,yPosition) direction.
I remember reading a similar problem on these forums, and it involved clones or something. Can anyone give me a simple solution to translating poly2 while leaving particle.getPolygon() alone?