This site requires JavaScript, please enable it in your browser!
Greenfoot back
Doge
Doge wrote ...

2014/1/5

Rotating from a point?

Doge Doge

2014/1/5

#
http://www.greenfoot.org/scenarios/10534 I don't want the tower to rotate from the middle, I want it to rotate from the tower! Any way I can achieve this?
danpost danpost

2014/1/5

#
There are (at least) two ways of accomplishing this: (1) make any turn adjustments, then (a) set location (b) turn 90 (c) move a 'radial' distance and (d) turn -90; or, (2) increase the transparent area above the image to make the point of rotation the center point
Doge Doge

2014/1/5

#
Do you have any advice about going about #1?
danpost danpost

2014/1/5

#
1
2
3
4
5
6
7
private int initX, initY;
 
public void addedToWorld(World w)
{
    initX = getX();
    initY = getY()-10; // adjust radius as needed
}
Adding the above to your actor subclass will save the center of rotation for the actor you added into the world. In your 'act' method
1
2
3
4
5
// any turning that needs done gets done before the following
setLocation(initX, initY); // put in center
turn(90); // alter rotation
move(10); // move from center (adjust radius as needed)
turn(-90); // reset rotation
The radial distance ('10' in the example) will be the distance between the center of the image and the center point of rotation (the tower).
You need to login to post a reply.