Single Timer on Multiple Objects
in
Programming Questions
•
1 year ago
Hi Forum, I'm having a mental block with how to deal with a timer issue...
I have an array of objects (circles) that I am testing to see if the mouse is positioned over.
I also have a timer that will trigger a function after the mouse stays over an object for a certain amount of time.
My problem is that if I mouse over a circle, the time overtop of it is additive, as it's only resetting the timer on a successful trigger call.
If i try to reset the timer when the mouse is not overtop of an object, it's resetting it continually, as I'm running through an array of objects to which some will be equated to false...
Here's My Code:
- for(int i = 0; i < circle.length; i++) {
- circle[i].update();
- if(circle[i].over == true) {
- if(millis() < newTimer + (trigTime * 1000) ) { // trigTime is an int
- // Nothing Here
- }
- else {
- // Send The Trigger Event
- trigger(i);
- // Reset The Timer
- newTimer = millis();
- }
- }
- else {
- // PROBLEM: Can't Figure Out How To Reset Timer For 'i' w/o Resetting All Continually
- // newTimer = millis();
- }
- }
Appreciated if anyone sees a strategy to deal with this...
Thanks in advance,
~ Jesse
1