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

2014/5/20

I am trying to rotate an object before the program actually starts up

kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
I am trying to rotate a car in order to drive the other direction. Here is my code so far,
public static int direction;
    public void act() 
    {
        if (atWorldEdge())
        {
            
            if(direction <0)
            {
                setLocation(605, getY());
            }
            else
            {
                setLocation(20, getY());
        }
        }  
        move(7);
    }
    public CarBlue(boolean d){
        if(d)
            getImage.mirrorVertically();
            turn(180);
    }
The getImage is the part I was trying to do to make it rotate but it needs the variable getImage, what do I need to add this variable or is there a better way to do this?
Zamoht Zamoht

2014/5/20

#
It's "getImage()".
kayuhnjayuhn kayuhnjayuhn

2014/5/20

#
This is my code now...
 public static int direction;
    public void act() 
    {
        if (atWorldEdge())
        {
            if(direction <0)
            {
                setLocation(605, getY());
            }
            else
            {
                setLocation(20, getY());
            }
        }  
        move(7);
    }
    public CarBlue(boolean d)
    {
        if(d)
        {
            getImage().mirrorVertically();
        }
            turn(180);
    }
What happens is the car gets to the edge and instead of wrapping around and starting at the other end of the screen it just stops at that end. How would I make it to go all the way around.
danpost danpost

2014/5/20

#
If this is all about rotating an actor 180 before the program is started up, then how about using the world constructor to do the job:
CarBlue blue = new CarBlue();
addObject(blue, /* whatever coordinates */ );
blue.turn(180);
If its image needs mirrored also, do it next:
blue.getImage().mirrorVertically();
Then the only code you need in the CarBlue class is the code for world wrapping:
public void act()
{
    if (getX() == 0) setLocation(getWorld().getWidth()-2, getY());
    if (getX() == getWorld().getWidth()-1) setLocation(1, getY());
    move(7);
}
kayuhnjayuhn kayuhnjayuhn

2014/5/21

#
Works great thanks again!
You need to login to post a reply.