We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i am kinda new to programming and processing and I am trying to create an animated sprite. I cannot make use of libraries. Underneath u can see my code, it loads the first image but it doesn't load the second nor the 3rd and forth though i put it in a loop. Please help!
PImage img1, img2, img3, img4; PImage [] imageArray = new PImage [4];
PImage img1, img2, img3, img4; PImage [] imageArray = new PImage [4]; void setup(){ size(400,400); background(150,150,150); //img1 = loadImage("img1.jpg"); //img2 = loadImage("img2.jpg"); //img3 = loadImage("img3.jpg"); //img4 = loadImage("img4.jpg"); imageArray[0] = loadImage("img1.jpg"); imageArray[1] = loadImage("img2.jpg"); imageArray[2] = loadImage("img3.jpg"); imageArray[3] = loadImage("img4.jpg"); } void draw(){ for(int i = 0; i < imageArray.length; i++){ image(imageArray[i], 200, 200); delay(10); if (i == 4){ i = 0; } } }
Answers
maybe your issue is somewhere else than you think
draw updates the screen only once at its end
so it might draw the images on top of each other, so you can see only the last one?
Try to draw them next to each other with
image(imageArray[i], 200 * i , 200);
See the FAQ about draw()
specifically
https://forum.processing.org/two/discussion/8085/i-display-images-in-sequence-but-i-see-only-the-last-one-why
you can say