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 › creating and accessing an array of objets
Page Index Toggle Pages: 1
creating and accessing an array of objets (Read 597 times)
creating and accessing an array of objets
Sep 6th, 2009, 8:30pm
 
Hello, sorry for posting 3 topics in a week, but processing is so addicting and I have a little problem that I spent a few hours.

I create 3 scrolling pgraphics that do their job, and now I would like to put those 3 objects in a array, so I can easily display hundreds of graphics with an iteration without copy/paste the code 100 times.

Here is the actualy code that works :
Code:


// what should go there to put objects in an array ?
 scrollTicker myScrollTicker1;  
 scrollTicker myScrollTicker2;  
void setup()

myScrollTicker1   = new scrollTicker(0, 100, 200,32);
myScrollTicker2   = new scrollTicker(0,200,300,30);
}
void draw()
{
 myScrollTicker1.move();
 myScrollTicker1.display();  

 myScrollTicker2.move();
 myScrollTicker2.display();  
   
 myScrollTicker3.move();
 myScrollTicker3.display();  


   // ... on so, up to 10000000
// my problem is not to write this iteration
// but to put the class myScrollTicker in an array
 
}


I've tried many things but it doesnt work (nullpointer exception). Could someone give me help to get this working with an array ?

Thanx a lot
Re: creating and accessing an array of objets
Reply #1 - Sep 6th, 2009, 8:41pm
 
Re: ... on so, up to 10000000
JESUS JOSEPH MARY AND HATSHEPSUT.
yeah, you want arrays bad.

scrollTicker[] myScrollTickers = new scrollTicker[1000];

void setup(){
 for (int i=0; i<myScrollTickers.length; i++){
   myScrollTickers[i] = new scrollTicker(blah blah blah blah);  
 }
}

void draw(){
 for (int i=0; i<myScrollTickers.length; i++){
    myScrollTickers[i].move();
    myScrollTickers[i].display();        
 }
}

:D
Re: creating and accessing an array of objets
Reply #2 - Sep 6th, 2009, 9:14pm
 
Thanks 10000000 times Wink
Page Index Toggle Pages: 1