i am trying to build an array of images to be displayed i looping, but I receive the error message that image cannot be solve as variable.
Here’s code:
int maxImages = 10;
int imageIndex = 0;
PImage[] images = new PImage [maxImages];
void setup() {
size(500, 555);
}
void draw(){
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( " i + 1 .jpg" );
image(images[imageIndex], 0, 0);
imageIndex = (imageIndex + 1)& image.length;
}
}
There is no image named " i + 1 .jpg" (everything inside quotes).
Read this reference to see how to add an integer to a string: + (addition) / Reference / Processing.org
The imageIndex is i in your for() loop and you do not need a separate variable.
You are displaying the images one after another in the for() loop!
Since the sketch window updates at the end of draw cycle you will only see the last image (once the code is corrected).
Code example and use of println() to help debugging:
int maxImages = 10;
int imageIndex = 0;
PImage[] images = new PImage [maxImages];
for (int i = 0; i < maxImages; i ++ )
{
// Important: Creates a String to use for image names
String imgNum = str(i); // this could be i+1 if your image names are 1 to 10
String imgExt = ".jpg";
String imgName = imgNum + imgExt;
// Shortcut for above:
//String imgName = i + ".jpg"; // This casts i to a String before adding to a String
println(imgName);
images[i] = loadImage(imgName);
// This will give errors since I do not have images.
// Console will show what is missing and that code used correct name!
imageIndex = (imageIndex + 1) & maxImages; // You are using a bitwise & here!
println(i, imageIndex); // See result of above math that is used in next loop.
}
The PImage array indexes from 0 to 9 and you load images (I am assuming) from 1.jpg to 10.jpg.
Add the 1 offset carefully in your code.