Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

enter image description here

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

share|improve this question
    
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? –  Sidar Oct 24 '12 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. –  BleedObsidian Oct 24 '12 at 19:39
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
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. –  BleedObsidian Oct 24 '12 at 20:04
    
Ah, way ahead of me then. Hopefully it's working now. –  Byte56 Oct 24 '12 at 20:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.