处理中 - 图像阵列错误 - "Type mismatch, 'processing .core.PImage' does not match.."



我正在尝试将图像加载到void setup()数组中,但是当我这样做时,它给了我这个错误:"类型不匹配,'处理.core。PImage"与"processing.core.PImage"不匹配。知道这意味着什么以及如何解决它吗?这是我的简化代码:

PImage [] goodCandy = new PImage [3];
int rand=(int) (2*Math.random()) +1;
void setup() {
for (int i=0; i<goodCandy.length; i++) {
  goodCandy = loadImage ("goodCandy" + i + ".png");
}
}
void draw() {
if (current=="play") {
loadStuff();
}
}
void loadStuff() {
image(goodCandy[rand], 0, 0, 50, 50);
}

我基本上想从数组中生成一个随机糖果并让它出现,但我收到此错误。我在名为 goodCandy1、2、3.png 的文件夹中有所有 3 张图像。有什么想法可以解决这个问题吗?

goodCandy[i] = loadImage("goodCandy" + i + ".png");

发生不匹配是因为您尝试将PImage存储在 PImage[] 中。请记住,loadImage()返回一个PImage而不是一个PImage数组,即PImage[]

最新更新