Processing.js array of pictures not showing properly

后端 未结 1 1149
不知归路
不知归路 2021-01-26 12:47

I am trying to take picture path data from my database and show it on the processing sketch like so this is Javascript file:



        
相关标签:
1条回答
  • 2021-01-26 13:16

    Think about it this way: you only have one img variable, so you're only ever showing a single image!

    Take a closer look at your loop:

     for(int i = 0; i <list.length; i++){    
            pic = list[i];
            img = loadImage(pic);
            println(pic);
        }
    

    You're looping through list and getting the images from it, but you're just constantly setting the img variable over and over again. At the end of this loop, img will just equal the last image in the list.

    Instead of using a single img variable, you probably want to use an array or an ArrayList. Here's a basic start:

    PImage[] images;
    
    void draw(){
        for (int i = 0; i < images.length ; i++){ 
            x = pad + (bs+pad)*i;
            y = pad;
            image(images[i],x,y,bs,bs);
        }
    }
    
    void change(String val){
        list = split(val," ");
        images = new PImage[list.length];
        for(int i = 0; i < list.length; i++){    
            images[i] = loadImage(list[i]);
        }
    }
    
    0 讨论(0)
提交回复
热议问题