I'm fairly new to programming and i'm trying to make a little game where you can control(rotate) a tank and different guns on top of the tank indepently. (I'm using slick)
during tank rotation the guns should rotate around the center of the tank-image because they are attached.
public void drawTankandGuns(){
tankImage.draw(position.x, position.y);
gunImage.draw(position.x+canonOffsetX, position.y+canonOffsetY);
}
public void rotateDuringMovement(){
gunImage.setCenterOfRotation(tankImage.getWidth/2-gunOffsetX,
tankImage.getHeight/2-gunOffsetY);
gunImage.rotate(angle);
tankImage.rotate(angle);
}
which works fine so far. gun is attached and rotates with tank. but if i want to rotate the gun without the tank (and tank is rotated already) and set the center of rotation back to the gun the gun-image is drawn back at its original position losing the position from the rotation around the tank...
edit: the solution was to use a different approach. draw the gunImage dependend on sin/cos of the tankImage rotation.