Array of text don't fade out until the last one is appended -


i want make group of array fade out until last array in group appended. example, use append create zoog[0], zoog[1], zoog[2], , want these 3 objects not fadeout until zoog[2] created , wait second, same situation zoog[3], zoog[4],zoog[5], these 3 objects don't fadeout until zoog[5] created. can make each object fadeout created.

zoog[]zoog = new zoog[1]; float count=0; int xpos =0; int ypos =0; string message="haha"; int ntextsize = 20; int nopacity =200; int thistime = 0; int thiscount = 0; //zoog zoog;  void setup() {   size(400, 400);     xpos = int(random(width/2-200, width/2+40));   ypos = int(random(height/2, height/2-40));   zoog[0] = new zoog(xpos,ypos,message,nopacity); }  void draw(){   background(255,255,255);    for(int i=0; i<zoog.length; i++){ //    if(millis()-thistime>4000){ //     zoog[i].disappear();  //    }     zoog[i].jiggle();     zoog[i].display();     } }   void mousepressed(){    count = count + 1;  // int thiscount = 0;   if(count%3 ==0){     xpos=int(random(30, width-30));     ypos=int(random(10, height-10));    }   else{     ypos = ypos+50; //   thiscount = thiscount +1; //   thistime = millis(); //  }   }    nopacity = int(random(100,255)); // text(message, xpos, ypos);  zoog b = new zoog(xpos,ypos,message,nopacity);  zoog =(zoog[]) append(zoog,b);  } 

zoog class

class zoog {   int x;   int y;   string thatmessage;    int opaci =0;    zoog(int xpo, int ypo, string thismessage, int opa) {     x = xpo;     y = ypo;     thatmessage = thismessage;      opaci = opa;   }    void jiggle() {      x = x+int(random(-2, 2));     y = y+int(random(-2, 2));   }    void display() {      fill(0, opaci);     text(thatmessage, x, y);     print("x position "+ x);     print("y position "+y);   }    void disappear() {     (int j=0; j<255; j++) {       opaci = opaci -j;     }   } } 

if understand correctly want make 3 zoogs , start fading 3 out until they're gone. if correct there couple of ways i'd go doing this.

first, wouldn't use array if you're dynamically updating amount inside it. if want i'd use, arraylists. here's javadocs reference. you'd initialize arraylist of zoogs , put zoog.add(new zoog...) in mousepressed. thing arraylists have number of member functions can manipulate them. instance, can check size of arraylist in draw function instead of time. once you're above 3 start fading first 3 out until they're dead (using zoog member function they're dead). can check "isdead" member function in draw loop , remove correct dead zoog while in loop.

here's rough implementation, assuming created isdead function in zoog class returns whether opacity greater 0:

void draw() {    (zoog zoog : zoogs) //for each statement simplifying code -                                   //says each zoog in zoogs    {       zoog.jiggle();       zoog.display();    }     if(zoogs.size() >= 3) {           for(int = 0; < 3; i++) {          zoogs.get(i).disappear();       }    }     if (zoogs.get(0).isdead() && zoogs.get(1).isdead() && zoogs.get(2).isdead()) {              zoogs.remove(2);              zoogs.remove(1);              zoogs.remove(0);     } } 

this no means perfect example shows how remove 3 zoogs @ time lessening opacity , checking whether dead. if you're clicking million times take while each chain of 3 die.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -