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

2016/5/24

Rotation of single object

The_Shados The_Shados

2016/5/24

#
I have multiple of the same objects on my world but I only want to rotate one of them. Can you help?
import greenfoot.*;

public class Dungeon1 extends World
{
    /**
     * Constructor for objects of class Dungeon1.
     * 
     */
    public Dungeon1()
    {    
        super(800, 800, 1); 
        
        addObject(new DeadEnd(), 550, 650);
        addObject(new Hall(), 550, 600);
        addObject(new Side(), 550, 550);
        addObject(new Corner(), 550, 500);
        addObject(new Side(), 500, 550);
        addObject(new Open(), 500, 500);
        addObject(new Hall(), 500, 450);
        addObject(new Hall(), 500, 400);
        addObject(new Side(), 450, 550);
        addObject(new Side(), 450, 500);
        addObject(new Corner(), 400, 550);
        addObject(new Side(), 400, 500);
        addObject(new Hall(), 400, 450);
        addObject(new Corner(), 400, 400);
    }
}
SPower SPower

2016/5/24

#
You'll have to be able to do something with the object after you've added it, so you're going to have to create it outside the call of addObject, like so:
// other stuff
Hall toRotate = new Hall(); // or any other object you want to rotate
addObject(toRotate, x,y);
toRotate.setRotation(angle);
// the rest
You need to login to post a reply.