处理中:启动画面背景错误

Processing: starting screen background error

我正在尝试为我在 Processing 中的第一个游戏创建开始屏幕背景,但它一直出错并显示以下消息:

>When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
  size(800, 800);
}
IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

我已经尝试通过关注消息和四处搜索来解决问题,但我没有设法解决它。

这是背景部分:

```
void setup() { 

bg = loadImage("rot.png");
size(800, 800);
strokeWeight( 10 );
frameRate( 30 );
background(bg);


```

如果需要,我会发送整个部分,但我认为这是存在问题的地方

提前致谢

processing中的settings()方法是3.0才加入的,很多人都忽略了它的存在。不过,这是一个很好的补充,它允许 setup() 方法不允许的东西(例如使用变量定义 window 大小)。

只需在新的 settings() 方法中移动 size() 行,完全按照程序所说。

(此外,如果您正在为草图设置动画,则应在 draw() 循环中绘制背景。)

PImage bg;

void settings() {
  size(800, 800);
}

void setup() { 
  bg = loadImage("rot.png");
}

void draw() {
  background(bg);
}

玩得开心!

确保您想要作为背景的图像与 canvas 具有相同的外形尺寸。因此,如果 canvas 大小为 800x800 像素,则图像必须相同。

祝你好运!