Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can I switch between classes using keyPressed() infinitely?

$
0
0

I have this code in which I made an animation being shown on the screen. I want to make the same animation with shades of red, green and blue (so three different functions, I guess?) and I want to be able to switch between them using keyPressed(). I got it working up to the point where I can actually switch, but only because of the order I put them in the keyPressed() code part. It isn't looping or something? Please help this beginner in Processing.

int max = 20; Kermit [] kermitCollection = new Kermit[max]; Kermit2 [] kermit2Collection = new Kermit2[max]; Kermit3 [] kermit3Collection = new Kermit3[max]; int h = 0; int i = 0; int j = 0; int k = 0; void setup(){ size(480,480); } void draw(){ for (int r=0; r<h; r++){ kermitCollection[r].display(); } for (int g=0; g<i; g++){ kermit2Collection[g].display2(); } for (int b=0; b<j; b++){ kermit3Collection[b].display3(); } } void keyPressed(){ if (h<max && key == 'r') { kermitCollection[h]= new Kermit(); h++; } if (i<max && key == 'g') { kermit2Collection[i]= new Kermit2(); i++; } if (j<max && key == 'b') { kermit3Collection[j]= new Kermit3(); j++; } }


Viewing all articles
Browse latest Browse all 2896

Trending Articles