Load Images into a class
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             Hello...
            
             
            
            
             
              
             
             
                  
             
             
              
             
             
              
             
             
                
             
             
            
             
            
            
             
              
             
             
              
             
             
                
             
             
              
             
             
              
             
            
            
             
             
           
 
            
           
             Basically I'm trying to load images into two classes. Here is my code.
            
            
             I've managed to display a card using loadImage function. The next bit is how do I load two images that are assigned to the class.
            
            
              int maxImages = 52;
             
             
              int imageInd = 0;
             
             
              PImage[] images = new PImage [maxImages];
             
             
              Card[] cards;
             
             
              void setup(){
             
             
                size(150, 200);
             
             
                for (int i=0; i <images.length; i++){
             
             
                  images[i] =loadImage(""+i+".png");
             
             
                  //images2[i]= loadImage(""+i+".png");
             
             
                }
             
             
                //for (int i=0; i<images.length; i++){
             
             
              //cards[i] = new Card(x, y, images,[i], i);
             
             
                }
             
             
              void draw(){
             
             
                image(images[imageInd],0,0);
             
             
              }
             
            
              class Card {
             
             
                // displays the card
             
             
                PImage img;
             
             
                float xP;
             
             
                float yP;
             
             
                float size;
             
             
                boolean matchedPairs;
             
             
                boolean show;
             
             
                int imgInd;
             
             
                Card (float x, float y, float size, PImage img, int imgInd) {
             
             
                  matchedPairs = false;
             
             
                  this.xP = x;
             
             
                  this.yP = y;
             
             
                  this.size = size;
             
             
                  this.img = img;
             
             
                  this.imgInd = imgInd;
             
             
                }
             
             
                void pairs() {
             
             
                  matchedPairs = true;
             
             
                }
             
             
                void showCard(){
             
             
                  show = true;
             
             
                }
             
             
                void displayCard() {
             
             
                  if (matchedPairs || show) {
             
             
                    image(img, xP, yP, size, size);
             
             
                  }
             
             
                }
             
             
              }
             
              
              
              1  
            
 
            