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

Why processing does not render and play sound in a FOR structure at the same time?? HELP

$
0
0

I am programming a Simon Game

` import processing.sound.*; import processing.serial.*; Quads[] seq = new Quads[100]; ArrayList seq2 = new ArrayList(); ArrayList seqP = new ArrayList();

SoundFile r, g, b, y; Quads red, green, blue, yellow; boolean turnoJugador = false; void setup() { //frameRate(300); size(200, 200); r = new SoundFile(this, "red.wav"); g = new SoundFile(this, "green.wav"); b = new SoundFile(this, "blue.wav"); y = new SoundFile(this, "yellow.wav"); red = new Quads(0, 0, color(255, 0, 0), r); green = new Quads(width/2, 0, color(0, 255, 0), g); blue = new Quads(0, height/2, color(0, 0, 255), b); yellow = new Quads(width/2, height/2, color(255, 255, 0), y); for (int i = 0; i < 100; i++) { int ranval = int(random(1, 5)); if (ranval == 1) { seq[i] = red; } else if (ranval == 2) { seq[i] = green; } else if (ranval == 3) { seq[i] = blue; } else if (ranval == 4) { seq[i] = yellow; } } } void draw() { //Render first quads red.onlyRend(); green.onlyRend(); blue.onlyRend(); yellow.onlyRend(); if (turnoJugador) { print(seq2.size() + "------------" + seqP.size()); if (seqP.size() >= 1) { for (int i = 0; i < seqP.size(); i++) { if (seq2.get(i) != seqP.get(i)) { background(0); textSize(20); text("GAME OVER", width/2, height/2); } } if (seq2.size() == seqP.size()) { turnoJugador = false; } } } else if (!turnoJugador) { delay(500); createArray(); turnoJugador = true; } }

void mousePressed() { if (red.x == 0 && red.yp == 0 && mouseX <= width/2 && mouseY <= height / 2) { r.play(); fill(120); rect(red.x, red.yp, width/2, height/2); seqP.add(red); } else if (green.x == width/2 && green.yp == 0 && mouseX >= width/2 && mouseY <= height / 2) { g.play(); fill(120); rect(green.x, green.yp, width/2, height/2); seqP.add(green); } else if (blue.x == 0 && blue.yp == height/2 && mouseX <= width/2 && mouseY >= height / 2) { b.play(); fill(120); rect(blue.x, blue.yp, width/2, height/2); seqP.add(blue); } else if (yellow.x == width/2 && yellow.yp == height/2 && mouseX >= width/2 && mouseY >= height / 2) { y.play(); fill(120); rect(yellow.x, yellow.yp, width/2, height/2); seqP.add(yellow); } }`

In another tab i have the class. In the finish is the problem. When the computer tries to make the random sequence the grey quads appears all at the same time when it finished to play all the sounds.< ------ HELP

`class Quads { int x, yp, wdh, hgh; color c; SoundFile s; Quads(int x1, int y1, int co, SoundFile ss) { x = x1; yp = y1; c = co; s = ss; }; void onlyRend() { fill(c); rect(x, yp, width/2, height/2); } void playIt() { s.play(); } void rendChange() { fill(120); rect(x, yp, width/2, height/2); } }

void createArray() { int j = int(random(seq.length)); seq2.add(seq[j]); seqP = new ArrayList(); for (int n = 0; n < seq2.size(); n++ ) { if (seq2.size() < 5) { delay(900); } else if (seq2.size() >= 5 && seq2.size() <= 10) { delay(850); } else if (seq2.size() >10 && seq2.size() <= 15) { delay(800); } else if (seq2.size() > 15 && seq2.size() <= 20) { delay(800); } else if (seq2.size() > 25 && seq2.size() <= 30) { delay(800); } else if (seq2.size() > 35 && seq2.size() <= 40) { delay(800); } seq2.get(n).playIt(); fill(120); rect(seq2.get(n).x, seq2.get(n).yp, width/2, height/2); } }`


Viewing all articles
Browse latest Browse all 2896

Trending Articles