TheBeliever12
TheBeliever12

Reputation: 97

JavaFX - Rotating On The Spot?

I have created a method that allows me to select a shape and rotate it. I was wondering if anyone knows how to rotate it 45 degrees on the spot.

RotateMethod

public void rotateObject() {
    int i=0;
    selectedShapes.get(i++).getTransforms().add(new Rotate(45, 360, 360));
}

The method gets the selected item and then rotates it when a button is clicked. Currently it will rotate it 360 degrees around the scene. I want it to rotate around the same spot. If there is a better way of implementing this rotate method please enlighten me. Thank You

EDIT:

After implementing the method stated below, the selected shape now rotates 45 degrees as required. However, it only rotates once, how can I re-write the method to allow it to rotate 45 degrees every time I click on my rotate button

public void rotateObject(ActionEvent event) throws IOException{
    int i = 0;
    selectedShapes.get(i++).setRotate(45);
}

Upvotes: 1

Views: 1050

Answers (1)

SedJ601
SedJ601

Reputation: 13858

Try

double angle[0] = {0};

public void rotateObject(ActionEvent event) throws IOException{
    int i = 0;//I don't understand this part of our code?
    angle[0] = angle[0] + 45;//Every time the button is pressed rotate 45 degrees.
    selectedShapes.get(i++).setRotate(angle[0]);
}

Upvotes: 1

Related Questions