Repeating function not showing
in
Programming Questions
•
1 year ago
Hey guys, when i press the keys 'a' and 's', the animation loads fine the first time round, however upon pressing them again, nothing loads, would anyone have any idea on how to solve this? Thanks! Your help is much appreciated.
Here is the code:
class Wave {
PVector loc;
int farOut;
Wave() {
loc = new PVector();
loc.x = 400;
loc.y = 300;
farOut = 1;
}
void update() {
farOut +=4;
}
void display() {
noStroke();
smooth();
fill(100,200,200);
ellipse(loc.x, loc.y, farOut, farOut);
}
boolean dead() {
if (farOut>1100) {
return true;
}
return false;
}
}
class Wave2{
PVector loc;
int farOut;
int farOutx;
Wave2() {
loc = new PVector();
loc.x = 400;
loc.y = 300;
farOutx = 1;
}
void rename() {
farOutx +=4;
}
void skey() {
noStroke();
smooth();
fill(244,245,94);
ellipse(loc.x, loc.y, farOutx, farOutx);
}
boolean dead() {
if (farOutx>1100) {
return true;
}
return false;
}
}
ArrayList<Wave> waves = new ArrayList<Wave>();
ArrayList<Wave2> wavex = new ArrayList<Wave2>();
import arb.soundcipher.*;
import arb.soundcipher.constants.*;
SoundCipher sc1 = new SoundCipher(this);
SoundCipher sc2 = new SoundCipher(this);
void setup(){
size(800,600);
frameRate(60);
ellipseMode(CENTER);
}
SoundCipher sc = new SoundCipher(this);
void draw(){
background(85);
if(key=='a'){
Wave w = new Wave();
waves.add(w);
}
for (int i=0; i<waves.size();i++){
waves.get(i).update();
waves.get(i).display();
if (waves.get(i).dead()) {
waves.remove(i);
}
}
if(key=='s'){
Wave2 s = new Wave2();
wavex.add(s);
}
for (int i=0; i<wavex.size();i++){
wavex.get(i).rename();
wavex.get(i).skey();
if (wavex.get(i).dead()) {
wavex.remove(i);
}
}
}
void keyPressed (){
int volume = 127;
float duration = 1.5;
if(key=='a'){
sc1.playNote(53,volume,duration);
}
if(key=='s'){
sc2.playNote(54,volume,duration);
}
}
1