We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm trying to load random images each time the function called using an array. That looks logical, but I get an error like "Cannot convert PImage to PImage[]" "Type mismatch, "processing.core.PImage" does not match with processing.core.PImage[]". Does it mean I can't use arrays with PImage,what am I doing wrong?
Simplified code:
PImage[] ImageArray= new PImage[7];
void setup() {
fullScreen();
for (int i=0; i<ImageArray.length; i++) {
ImageArray=loadImage(i + ".png");
}
}
void draw() {
background(0);
if (frameCount % 2 == 0) {
image(ImageArray[(int)random(7)], 0, 0);
}
}
Answers
line 7 ...[i]=
%2..... better %44 or so
display the image throughout
the if-clause only changes a var that is the index for the array,ok?
int indexArray;
image(ImageArray[indexArray], 0, 0);
Well %2 is just a random number I wrote when I was rewriting the code, I'm using %60 in the original code.
I didn't get why you used the indexArray integer. It works when I write that " image(ImageArray[(int)random(7)], 0, 0);" I want to load a random image between 0 and 7. With indexArray it only loads the image[0]
well, when the image() command is inside if, the image would only appear briefly
better show the image outside the if as shown and say
if (frameCount % 2 == 0) {
indexArray= int(random(7));
}
image.....
Heck, I forgot to mention it before. I want the image to appear briefly.
;-)