More timer questions
in
Programming Questions
•
1 month ago
Well - I have a timer function, but I can't seem to make it work correctly - this is just a part of my sketch, I am doing smaller blocks to get everything to work - any help would be greatly appreciated! Cheers!
In this block I would like to:
click the bowl
bell sounds
timer starts
circles move across the screen until time is up
- Maxim maxim;
- AudioPlayer player_open_bell;
- int threshold;
- int prevMillis=0;
- float x = 0.0;
- Button a;
- PImage bowl1;
- boolean playing = false;
- void setup()
- {
- size(1024, 768);
- // test for new timer
- background(#FFFFFF);
- smooth();
- threshold = 1000;
- fill(#FFFFFF,0,0,5);
- noStroke();
- bowl1 = loadImage("bowl1.png");
- a = new Button("bowl1.png", 100, 100, 50, 30);
- maxim = new Maxim(this);
- player_open_bell = maxim.loadFile("start_bell.wav");
- player_open_bell.setLooping(false);
- }
- void draw()
- {
- fill(0);
- PImage uiImage = loadImage("bowl1.png");
- image (uiImage, 100, 100);
- if (a.mousePressed())
- {
- //rings once timer starts and goes for one second-- won't do again if pressed
- player_open_bell = maxim.loadFile("start_bell.wav");
- player_open_bell.stop();
- player_open_bell.cue(0);
- player_open_bell.play();
- player_open_bell.setLooping(false);
- println("works!");
- startTimer();
- }
- }
- void startTimer()
- {
- if (millis() - prevMillis >= threshold)
- {
- ellipse(x, height/2, 50, 50);
- //tint(255, 126);
- x += 50;
- //prevMillis = millis();
- prevMillis += threshold;
- }
- }
1