I am using Java Slick StateBaeedGame and want to rotate my rectangles for my collisions, I know this is possible to do for visual purposes using the Graphics or Graphics2D object but that does not modify the rectangle itself, the rectangle that is originally listed with the variables and called for in the graphics method does not rotate, to make things more clear here is some code:
java.awt.geom.Rectangle2D.Float rectTwo = new Rectangle2D.Float(460 + buckyPositionX, 50 + buckyPositionY, 100, 100);
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
worldMap.draw(buckyPositionX,buckyPositionY); //draw the map at 0,0 to start
bucky.draw(shiftX,shiftY); //draw bucky at 320, 160 (center of the screen)
g.rotate(460 + buckyPositionX, 50 + buckyPositionY, 40);
g.fillRect((float)rectTwo.getX(), (float)rectTwo.getY(), (float)rectTwo.getWidth(), (float)rectTwo.getHeight());
}
The rectangle rectTwo will be shown as rotation when I load my GUI but it is not actually rotated, if I test for a collision the rectangle is still at 0 degrees.
So, how do I get my rectangle variable to change its angle?
Generally, you can’t.
What you can do, is transform the path of the shape…
This isn’t much use to you right now, but you can then use a
Path2D#appendto append the path back into aShapeobject…Which would allow you to paint it…
This, of course, assumes that your
Graphicscontext is aGraphics2Dinstance.This also means, that you can’t maintain a direct reference to a
Rectange2D, but would need to useShapeinstead.