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:

            rotate += rotateSpeed * delta;
            image.rotate(rotate - image.getRotation());

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

For example:

enter image description here

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

  • \$\begingroup\$ 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? \$\endgroup\$
    – Sidar
    Oct 24, 2012 at 18:07
  • \$\begingroup\$ 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. \$\endgroup\$ Oct 24, 2012 at 19:39

1 Answer 1


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.

  • \$\begingroup\$ 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. \$\endgroup\$ Oct 24, 2012 at 20:04
  • \$\begingroup\$ Ah, way ahead of me then. Hopefully it's working now. \$\endgroup\$
    – House
    Oct 24, 2012 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .