So im trying to get an array of images to loop however, i have set up the array and loops correctly, however it only shows one image where as i need it to loop and then stop at the last image.
//explosion images
PImage[] explosions = new PImage[6];
//loop to create load images into explosions[i]
for (int i = 0; i < explosions.length; i++){
explosions[i] = loadImage("images/expl"+i+".png");
}
for(int i = 0; i < explosions.length; i++){
imageMode(CENTER);
image(explosions[i], player_1.x, player_1.y, resize,resize);
}
This is what i have so far i just cant figure out how to loop it. Anything of help would eb good
I believe this is the issue since all the images get drawn on the same place during one frame, having the result that you only see the top image (last one of the array).
I suggest making a float counter and rounding that to an int. then just make the counter every frame something like .1 bigger the after a few frames it will get rounded to a new number giving you a new image
<PImage explosions = new PImage[6];
float counter = 0;
void draw(){
counter += .1;
int i = round(counter);
image(explosions[i],0,0);
if(counter > 5.4){ //higher then 5.4 would get rounded to six which is out of your array
counter = 0; // reset counter
}
}/>
Sorry if the code doesn’t show up properly this is my first time posting code on this forum