I am making a simple program to familiarize myself with GreenFoot where a person throws a toy a random direction for a random distance, and you control a dog and pick it up. One problem I found strange is that when I use the mirrorHorizontally() method the dog (which is represented by the wombat image that came with the program) changes from brown to orange permanently. I want to know why this is happening. Here is the code for the movement of the dog (I called the class Raider because that is the name of my dog):
public class Raider extends Actor
{
private int raiderSpeed = 2;
private boolean facingRight = true;
public void act()
{
if( Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown("w" ) )
{
setLocation( getX(), getY() - raiderSpeed ) ;
}
if( Greenfoot.isKeyDown("down") || Greenfoot.isKeyDown("s") )
{
setLocation( getX(), getY() + raiderSpeed ) ;
}
if( Greenfoot.isKeyDown("left") || Greenfoot.isKeyDown("a") )
{
if(facingRight)
{
GreenfootImage image = getImage();
image.mirrorHorizontally();
}
facingRight = false;
setLocation( getX() - raiderSpeed, getY() ) ;
}
if( Greenfoot.isKeyDown("right") || Greenfoot.isKeyDown("d" ) )
{
if(!facingRight)
{
GreenfootImage image = getImage();
image.mirrorHorizontally();
}
facingRight = true;
setLocation( getX() + raiderSpeed, getY() ) ;
}
}
}
