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

2021/6/23

setImage

Gabe1098 Gabe1098

2021/6/23

#
I'm having trouble with setImage(); every time I do it I get terminal errors can someone help me? here's my code so far
if (Greenfoot.isKeyDown("c")) {
            Greenfoot.setImage("Banana");
        }
Gbasire Gbasire

2021/6/23

#
you're doing it wrong. 2 ways of doing it right : 1 : basic :
if(Greenfoot.isKeyDown("c"))
    setImage("Banana.png");
2 : if you have created a GreenfootImage before :
//at the start
GreenfootImage banana = new GreenfootImage("banana.png);
//then
if(Greenfoot.isKeyDown("c"))
    setImage(banana)
Gabe1098 Gabe1098

2021/6/23

#
Gbasire wrote...
you're doing it wrong. 2 ways of doing it right : 1 : basic :
if(Greenfoot.isKeyDown("c"))
    setImage("Banana.png");
2 : if you have created a GreenfootImage before :
//at the start
GreenfootImage banana = new GreenfootImage("banana.png);
//then
if(Greenfoot.isKeyDown("c"))
    setImage(banana)
both gave me terminal errors
Gbasire Gbasire

2021/6/23

#
remember that you must have a file named "Banana.png" in the images folder of your Project folder
Gabe1098 Gabe1098

2021/6/23

#
Gbasire wrote...
remember that you must have a file named "Banana.png" in the images folder of your Project folder
I do
Gbasire Gbasire

2021/6/23

#
I just realised I did some typo errors in my previous message, sorry here are the correct lines of code :
if(Greenfoot.isKeyDown("c"))
    setImage(new GreenfootImage("Banana.png"));
and
//at the start
GreenfootImage banana = new GreenfootImage("Banana.png");
//then
if(Greenfoot.isKeyDown("c"))
    setImage(banana);
be sure you also use the correct capitalization, the file must be "Banana.png" with a capital B
Gabe1098 Gabe1098

2021/6/24

#
yes I noticed that and I fixed it I will see if it fixes tomorrow
Gabe1098 Gabe1098

2021/6/24

#
Gbasire wrote...
I just realised I did some typo errors in my previous message, sorry here are the correct lines of code :
if(Greenfoot.isKeyDown("c"))
    setImage(new GreenfootImage("Banana.png"));
and
//at the start
GreenfootImage banana = new GreenfootImage("Banana.png");
//then
if(Greenfoot.isKeyDown("c"))
    setImage(banana);
be sure you also use the correct capitalization, the file must be "Banana.png" with a capital B
yes I noticed that and I fixed it I will see if it fixes tomorrow
You need to login to post a reply.