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

2018/1/25

Why isn't this working?

ORSODO ORSODO

2018/1/25

#
private GreenfootImage image1=new GreenfootImage("car1.png");
private GreenfootImage image2=new GreenfootImage("car2.png");
public void act ()
{
if (Greenfoot.isKeyDown ("up") && getImage ()==image1) {setLocation (getX()+1, getY());} 
if (Greenfoot.isKeyDown("left") && getImage()==image1) {setImage (image2);}
}
danpost danpost

2018/1/25

#
You probably never set the image of the actor to 'image1'. Try adding the following to the class:
public Car()
{
    setImage(image1);
}
ORSODO ORSODO

2018/1/25

#
it doesn't work.. it's not even moving
danpost danpost

2018/1/25

#
ORSODO wrote...
it doesn't work.. it's not even moving
Please provide the entire class code for examination.
You need to login to post a reply.