【问题标题】:I am having trouble to set color to my Greenfoot MyWorld class我无法为我的 Greenfoot MyWorld 课程设置颜色
【发布时间】:2018-02-16 22:13:17
【问题描述】:

我是编程新手,我们有一个关于制作 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);
}

【问题讨论】:

标签: java compiler-errors awt cannot-find-symbol greenfoot


【解决方案1】:

Actor中的方法叫做setImage,但是the similar method in World is called setBackground。有点混乱,我知道。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    相关资源
    最近更新 更多