Need help creating a counter for a game

Hi! I’m new to openframeworks and was trying to add a counter to my game. I need the time to start at 0 and start counting when the game begins, but I don’t know how to do that. A lot of tutorials that I’ve watched teach you how to make a countdown timer, but I need the opposite of that and can’t understand how to do it.
Any help will be appreciated :slight_smile:

Hi @Luu16 , ofUtils::getElapsedTimeF() will give you the time (as a float) that has elapsed since the application has started. You can calculate the difference from two calls to this function. Hope this helps!

Thank you for the help! But I can’t seem to find out how to display it in the screen. I tried applying it to the :draw part of the code but nothing shows

Hey to draw it to the screen, have a look at using ofDrawBitmapString() in ofApp.draw(). A float of the elapsed time can be converted to a string. Or use an int to get whole seconds. So something like this (in psudeo-code):

int elapsedTime = ofGetElapsedTimeF() - startTime;
// set the color to white
// draw it in the upper left of the screen at (20, 20)
ofDrawBitmapString("elapsed time: " + ofToString(elapsedTime), 20.f, 20.f);

std::to_string() will also convert a number to a string.