Call an ofApp function from ofTimer Scheduler

I would like to call a function of ofApp in the thread of Scheduler.

I pasted the ofTimer example in my ofApp.h and I would like to call a function of ofApp every time interval.
How can I access to that function?

Thank you

Hi @kronikle,

Not sure how to use ofTimer really.

I would use something like this :

in ofApp.cpp::update():

if(ofGetElapsedTimef() % periodOfTime == 0){
// do something 

where ofGetElapsedTimef is the time passed since the program started,
periodOfTime is the amount of time (in this case seconds) for which you want your code to wait for.

You can use ofGetElapsedTimeMillis, if you want more precison, don;t forget to multiply periodOfTime by 1000 though.

Hope this helps,



1 Like