Stopwatch is slow

I think I have what should be a correctly functioning stopwatch. I set up a timer to repeat a function that adds 1 to the tenths-of-a-second and when that equals 10, I reset it back to 0 and add one to the next part of the timer (seconds in this case).

The timer is: “tmr=timer.performWithDelay(100, change, 0)”

where “change” is the function that adds to the display. This should have it repeat every tenth of a second, right? But the timer seems to be off. It is much slower than my real watch. I have a feeling this is because it’s taking too long to calculate what should be done with the display, but I’m not sure how to fix it. Any help is appreciated. [import]uid: 30592 topic_id: 9446 reply_id: 309446[/import]

If your app runs really quickly (IE can guarantee there’s no slowdown so its always at 30 or 60fps), you could just increment your counter within an enterFrame event - but again you can’t factor in other things.

I’ve not looked, but is there no way of hooking into the system clock? Then you’d just get the time when the stop watch started, and the difference between then and now is how long it has been running. [import]uid: 46639 topic_id: 9446 reply_id: 34601[/import]

Yes. An enterframe event might work, but it’s pretty inflexible when it comes to interactivity. Having it retrieve the time from the system clock might work, are you referring to adding in an event.time, a system.getTimer, or an os.time?

Another thing I forgot to mention earlier was that I changed the iteration time on the timer to 1000 (milliseconds) and it got more accurate, only falling behind by a whole second after about a minute. It could be a simulator error, but I don’t know if building it to the device would fix it, since the simulator is supposed to work like the device I’m simulating. [import]uid: 30592 topic_id: 9446 reply_id: 34610[/import]

What are you using to display the text? If you’re using display.newText, then you have a serious bottleneck. This is not intented to be used with a constantly changing text. This is not a corona-specific issue. This might seem trivial but OpenGL doesn’t know how to handle text. So what the function does is generate a texture with a text on it. Every time you change the text.

You might want to look into Bitmap Fonts, which has been used in video games since pong (just a guess :wink: ) [import]uid: 51516 topic_id: 9446 reply_id: 34613[/import]

Wow. I’d say that’s most likely my problem. I am using newText for it, so I should probably check out these bitmap fonts. Thanks for the help!

edit: can anyone give me more information about the bitmap fonts? I know how to put them into my app, but if I shouldn’t use display.newText, how should I implement it? And where do I get the fonts? [import]uid: 30592 topic_id: 9446 reply_id: 34637[/import]

Unfortunately, there is no support for Bitmap Fonts in Corona. You can either search for a library in the Code Exchange section or roll your own.

There are plenty of Bitmap Fonts dedicated website, and even tools to generate them from True Type Font. Just google it. [import]uid: 51516 topic_id: 9446 reply_id: 34653[/import]

Thanks! I’ll try that. [import]uid: 30592 topic_id: 9446 reply_id: 34692[/import]