Problem with removing objects
in
Programming Questions
•
2 years ago
I'm working on a program right now that starts by creating 28 rectangle objects in random positions and animates them to bounce in the window. I'm trying make it so that as there is input (a key press currently), one rectangle is removed. And the count of removed rectangles goes up by one accordingly. The other rectangles continue to animate, until they are all removed.
But the problem I'm running into is that when is removing, it is doing it multiple times for ever key press, when it's supposed to do one. I think it has something to do with the frame rate but I'm not sure.
If anyone could help me I'd be really grateful!
- int numPerson = 28;
- int numRem = 0; //number removed
- person[] indPerson = new person[numPerson];
- read tdisplayed;
- void setup() {
- size(1440,900);
- frameRate(30);
- smooth();
- for (int i = 0; i < numPerson; i++) {
- indPerson[i] = new person();
- }
- tdisplayed = new read();
- }
- void draw() {
- background(0);
- for (int t = 0; t < numPerson; t++) {
- indPerson[t].display();
- indPerson[t].move();
- }
- if(keyPressed) {
- if (key == 'b') {
- numPerson--;
- numRem++;
- println(numPerson);
- println(numRem);
- }
- }
- }
1