java - How can I stack 20 "plate" looking objects (ellipse shape) to 20 with if or while statements? My functions are not working correctly -


i trying code in java 20 plate stack using key pressed function stack new plate , mouse click function make individual plates disappear 1 one 0. cannot figure out why functions won't work not command them, please help.

 // declare global (shared) variables here  float plate1x = 50;  float plate1y = 200;  int platecount = 20;    // not write statements here (must inside methods)      // add statements run once when program starts here.  example:   void setup() {     size(400,400);    plate1x = 200;    plate1y = 50;    background(255);    plate1x = width/2;    plate1y = height-25;     } // end of setup method    void draw()  {    // declare local variables here (new each time through)     // add statements run each time screen updated here    ellipse(plate1x, plate1y, 200,50);    stroke(0);    fill(50,100,40);  }         // screen repainted automatically @ end of draw method     // end of draw method   // add other methods here    void keypressed() {    plate1y = -25;    while( plate1y < height)       ellipse(plate1x, plate1y, 200,50);       plate1y = plate1y - 10;    }    void mousepressed() {      while( plate1y <= -205)      ellipse(plate1x, plate1y, 200,50);       plate1y = plate1y + 10;    } 

you need draw each plate every time draw() method called, typically happens 60 times second. might keep coordinated of each plate in 2 arrays platex[] , platey[] numplates keeping track of how many plates there are. can add or subtract entries array in keypressed() , mousepressed() methods, don't actual drawing there.

// declare global (shared) variables here  float plate1x = 50;  float plate1y = 200;  int platecount = 20;  int numplates = 1; float platex[] = new float[platecount]; float platey[] = new float[platecount];   // not write statements here (must inside methods)      // add statements run once when program starts here.  example:   void setup() {     size(400,400);    background(255);    plate1x = width/2;    plate1y = height-25;    platex[0]=plate1x;    platey[0]=plate1y;    } // end of setup method    void draw()  {    // declare local variables here (new each time through)     // add statements run each time screen updated here    for(int i=0;i<numplates;++i)     ellipse(platex[i], platey[i], 200,50);    stroke(0);    fill(50,100,40);  }     // screen repainted automatically @ end of draw method     // end of draw method   // add other methods here    void keypressed() {    plate1y -= 25;    if( plate1y > 0) {    platex[numplates]=plate1x;    platey[numplates]=plate1y;      ++numplates;    }  }      void mousepressed() {      --numplates;      plate1y += 25;    } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -