# How can I set the rotation of a shape to the same as my image?

The way you set rotations of images is different from setting shape rotations. So how can I make the shape have the same rotation as my image?

This is how my image rotates:

if(input.isKeyDown(Input.KEY_RIGHT))
{
rotate += rotateSpeed * delta;
image.rotate(rotate - image.getRotation());
}


How can I get the same effect but with a shape?

For example: How can I get that rectangle to be at the same rotation as the car?

• Shouldn't you be rotating the complete sprite and not just the image? Otherwise couldn't you just set the rectangles rotation to that of your image? Oct 24, 2012 at 18:07
• Well the thing is the way you rotate the shape is different to the way you rotate the shape. The shape, you give it a number and it adds it to the current rotation. The image you give it a number say 90 and it sets the rotation to 90. Oct 24, 2012 at 19:39

If you're using Slick2D to create the rectangle. Slick2D has a Shape class that can be used to describe such things (rectangles, circles, etc.).

I imagine you're using a shape like this for collision because it has methods like intersect()(link) that allow you to detect such things.

Shape also has a nice method called transform()(link). It can be used to apply a transform to your shape. Transforms are essentially matrix operations. Luckily you don't need to know too much about the matrix operation because it's easy to create transforms. Transform has a static method called createRotateTransform. You can use this to specify a rotation to create a transform to apply to the shape.

So the short of it would be, use something like this:

rotatedCarShape = carShape.transform(Transform.createRotateTransform(radiansToRotate)));


Remember that transform does not alter the original shape, so you don't have to worry about the rotations adding up, but you do need to remember to draw the correct transformed shape.

• This is what I was doing but it wasn't working, it was not rotating at the same speed as the car. Then I realized that the shape transform need radians not degrees. Oct 24, 2012 at 20:04
• Ah, way ahead of me then. Hopefully it's working now.
– House
Oct 24, 2012 at 20:05