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

2012/5/13

Actor Rotation

Matt Matt

2012/5/13

#
I am creating a car park game, so their are a number of cars that face in different directions. If I put
1
setRotation(90);
into the actor code it makes every one of that actor face in that direction. But i will want the particular actor to face in multiple directions. I have been using
1
addObject(new Tree(),2,23); //Adds a Tree to the world at the particular co-ordinate
within the world coding, is their any way I can alter this so each object faces a particular direction.
SPower SPower

2012/5/13

#
YES. Checkout the turnTowards method in Actor (you must have Greenfoot 2.2)
Matt Matt

2012/5/14

#
1
2
3
4
5
turnTowards
 public void turnTowards(int x,
                        int y) Turn this actor to face towards a certain location.
 
Parameters:x - The x-coordinate of the cell to turn towardsy - The y-coordinate of the cell to turn towards
Could you give me an example of how I could use this
trash1000 trash1000

2012/5/14

#
1
2
3
4
5
private Object obj1 = new Object(); // the object you want your actor to turn towards
 
public void turnToObject() {
    turnTowards(obj1.getX(), obj2.getY());
}
Simple solution but not tested.
You need to login to post a reply.