We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Problem understanding array
Page Index Toggle Pages: 1
Problem understanding array (Read 268 times)
Problem understanding array
Nov 9th, 2008, 4:01pm
 
I got 2 problem and really in need of help to solve it.

1.
 Is there any way that I can call files directly from the data folder..? because after i look through some example but i totally can't understand. =x

2.
 I am trying to write a array which i can load mutiple level and create a loading of random files. I know my problem is the code i wrote on the 1st line, but I think I wrote it wrongly that's why it doesn't work out. Can anyone please tell me my mistake.



//Problem in loading the ImageNO array
PImage BGImg [int(new ImageNO = 0)];
   
     

String BGImg1FileNames[] = {

"levelOne/0.jpg",
"levelOne/1.jpg",
"levelOne/2.jpg",
"levelOne/3.jpg",
"levelOne/4.jpg"

};


String BGImg2FileNames[] = {

"levelTwo/0.jpg",
"levelTwo/1.jpg",
"levelTwo/2.jpg",
"levelTwo/3.jpg"

};

String BGImg3FileNames[] = {

"levelThree/0.jpg",
"levelThree/1.jpg",
"levelThree/2.jpg",
"levelThree/3.jpg"

};

//retrive Imageno. lenght
int TOTAL_IMAGES = BGImg1FileNames.length;
int TOTAL_IMAGES2 = BGImg2FileNames.length;
int TOTAL_IMAGES3 = BGImg3FileNames.length;


//image loading array
PImage[] BGCountImg = new PImage[TOTAL_IMAGES];
PImage[] BG2CountImg = new PImage[TOTAL_IMAGES2];
PImage[] BG3CountImg = new PImage[TOTAL_IMAGES3];




void setup()
{
 size(1024,768);
 
 
 for (int i = 1; i<TOTAL_IMAGES; i++){
     println("loading img "+i);      
     BGCountImg[i] = loadImage(BGImg1FileNames[i]);
     //println("timer count img" + timerImgFileNames[i]);
   }
   
  for (int j = 1; j<TOTAL_IMAGES2; j++){
     //println("loading img "+i);      
     BG2CountImg[j] = loadImage(BGImg2FileNames[j]);
   }
   
   for (int k = 1; k<TOTAL_IMAGES3; k++){
     //println("loading img "+i);      
     BG2CountImg[k] = loadImage(BGImg3FileNames[k]);
   }
   
     BGImg[1] = BGCountImg[int(random(TOTAL_IMAGES))];
     BGImg[2] = BG2CountImg[int(random(TOTAL_IMAGES2))];
     BGImg[3] = BG3CountImg[int(random(TOTAL_IMAGES3))];
     
     
}

void draw()
{

 image(BGImg[ImageNo],0,0);
 println("ImageNO" + ImageNO);

}

void mouseReleased()
   {
     ImageNO = ImageNO+1 ;
   }
Re: Problem understanding array
Reply #1 - Nov 9th, 2008, 5:49pm
 
This will load 3 images in an array :

Quote:
// declare an array of PImages
PImage[] myImages;

// initialize the array;
myImages = new PImage[3]; // say I want 3 images

// fill the array
for (int i = 0; i < 3; i++) {
 myImages[i] = loadImage("my_image_" + i + ".png");
}
Re: Problem understanding array
Reply #2 - Nov 10th, 2008, 3:36am
 
hey thanks antiplastik.
but that not i am looking for.. but thanks so much for your help. BTW i manage to found one of my solution for my second problem...

http://processing.org/learning/topics/directorylist.html

But I am still stuck with my 1st problem.
because right now i load all my image into 3 different array. but i am going to use another array to control this 3 array that's the array i can't really figure out.
which is the the 1st line of my code.
Re: Problem understanding array
Reply #3 - Nov 10th, 2008, 8:51am
 
First problem: I see nowhere declaration of ImageNO. It looks like an integer, so you cannot do new ImageNO (this syntax is for classes).

From what I understand of your code, you should just declare:

int ImageNO;
PImage[] BGImg = new PImage[3];

and

void mouseReleased()
   {
ImageNO = ++ImageNO % 3;
   }

The % 3 is to avoid going beyond the limits of the array (cycling).
Re: Problem understanding array
Reply #4 - Nov 11th, 2008, 10:27am
 
hey really thanks so much for helping me out.
it work out in a way..=D
cheers..
thanks everyone for helping out..
Page Index Toggle Pages: 1