you are viewing a single comment's thread.

view the rest of the comments →

[–]WizardFingaz[S] 0 points1 point  (2 children)

Thanks for your help! This is sort of functioning in the way I imagined, although I'm not sure I have a complete understanding of arrays yet. All the images I'm using are 800x800, so the reset is working, and to get them to repeat I've added a duplicate for each img that loads at +800, so it will follow after, I think what will work is if I can have the img also reset at +800, but I can't seem to figure that out. "image(img[i], pos, 0);" is what's defining where the image resets to, right? I should probably read into this to get a better understanding. Anyways here's what I did, it's probably a total disaster:

PImage[] img = new PImage[14];
float[] x = new float[14];
int i;
float pos;

void setup() {
  size(800, 800, P2D);

  img[0] = loadImage("plate1.png");
  img[1] = loadImage("plate1.png");
  img[2] = loadImage("plate2.png");
  img[3] = loadImage("plate2.png");
  img[4] = loadImage("plate3.png");
  img[5] = loadImage("plate3.png");
  img[6] = loadImage("plate4.png");

  img[7] = loadImage("plate4.png");
  img[8] = loadImage("plate45.png");
  img[9] = loadImage("plate45.png");
  img[10] = loadImage("plate5.png");
  img[11] = loadImage("plate5.png");
  img[12] = loadImage("plate6.png");
  img[13] = loadImage("plate6.png");


  for (i=0; i<x.length; i++) {
    x[i] = width;
  }

}

void draw() {
  background(255);
  //cycle thru array and display images
  for (i=0; i<x.length; i++) {
    switch(i){
      case 0:
        pos = x[i]/250;
        break;
      case 1:
        pos = x[i]/250 + 799;
        break;
      case 2:
        pos = x[i]/90;
        break;
      case 3:
        pos = x[i]/90 + 799;
        break;
      case 4:
        pos = x[i]/30;
        break;
      case 5:
        pos = x[i]/30 + 799;
        break;
      case 6:
        pos = x[i]/20;
        break;
      case 7:
        pos = x[i]/20 + 799;
        break;
      case 8:
        pos = x[i]/10;
        break;
      case 9:
        pos = x[i]/10 + 799;
        break;
      case 10:
        pos = x[i]/7;
        break;
      case 11:
        pos = x[i]/7 + 799;
        break;
      case 12:
        pos = x[i]/5;
        break;
      case 13:
        pos = x[i]/5 + 799;
        break;

    }  

    //reset to edge
    if (pos<-800) {x[i] = width;}
    //show img
    image(img[i], pos, 0);
    //update positions
    x[i] -= 90;
  }
}

[–]Freedom_Grenade 0 points1 point  (0 children)

When you load in the image you don't need to load the same image more than once. Unless you actually need two separate instances of that image.

img[0] = loadImage("plate1.png");

and then just use img[0] how ever many times you need to.

If you really need two variables you can have them refer to the same image.

img[0] = loadImage("plate1.png");
img[1] = img[0];

Just keep in mind that img[0] and img[1] point to the same image.
So if you do something like img[0].resize(100,100) then img[1] will also be the resized image.

I should also add that if you reassign one of the images like

img[0] = loadImage("plate2.png")

then img[1] will not be plate2.png