Home Ask Login Register

Developers Planet

Your answer is one click away!

ItzBenteThePig February 2016

Rotating image in java

I'm trying to make a game where the player sometimes have to rotate, but I can't figure out a way to make it rotate more each time, here's what I've got: Graphics2D g2d = (Graphics2D) g;

    AffineTransform at = new AffineTransform();

    at.translate(300, Main.height - 115);

    if(rotateright) {
        at.rotate(Math.PI / 15);
    } else if(rotateleft) {
        at.rotate(Math.PI / 15);

    }

    at.scale(0.125, 0.125);

    at.translate(-texture.getWidth() / 2, -texture.getHeight() / 2);

    g2d.drawImage(texture, at, null);

This method makes it rotate just fine, but I can't find a way to make it rotate more each time, so this method pretty much just rotates it, but only once, and then it just stops. Is there anyway to add to the rotation or something?

Answers


Matthias Huttar February 2016

you're always starting of with the image in the normal rotation (0 deg/RAD rotated), and then radiating it by PI/15 RAD. if you want it to rotate over time, you will need to multiply PI/15 with a value that will be changing over the duration of your animation.

Post Status

Asked in February 2016
Viewed 1,316 times
Voted 6
Answered 1 times

Search




Leave an answer


Quote of the day: live life