0

我是编程新手,我们有一项关于制作 Greenfoot 游戏的任务。现在我正在尝试设置一些颜色,MyWorld但遇到了一些问题。我在MyWorld文件中的代码是

   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);

}

它返回一个错误

找不到符号 - 方法 setImage(greenfoot.GreenfootImage)

Actor正常工作的类之一上的相同代码。

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

1 回答 1

0

Actor 中的方法称为 setImage,但World 中的类似方法称为 setBackground。有点混乱,我知道。

还要注意 setColor 本身不做任何事情,它只是设置绘图颜色。如果您想用该颜色填充图像,请bgBig.fill在调用 setColor 后调用。

于 2018-02-17T09:04:37.557 回答