简体   繁体   中英

I am having trouble to set color to my Greenfoot MyWorld class

I am new to programming and we have an assignment about making a Greenfoot game. now I am trying to set some colors to MyWorld but having some problems. My code in MyWorld file is

   public MyWorld()
{    
    // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
    super(600, 400, 1); 
    GreenfootImage bg = new GreenfootImage(600, 400);
    bg.setColor(new Color(0, 0, 250, 9));
    setImage(bg);

}

and it is returning an error

cannot find symbol - method setImage(greenfoot.GreenfootImage)

The same code on one of the Actor classes working normally.

    public BgCells(){
    GreenfootImage bgBig = new GreenfootImage(200, 200);
    bgBig.setColor(new Color(0, 0, 250));
    setImage(bgBig);
}

The method in Actor is called setImage, but the similar method in World is called setBackground . A bit confusing, I know.

Note also that setColor doesn't do anything by itself, it just sets the drawing colour. If you want to fill the image with that colour, call bgBig.fill after calling setColor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM