#Java Swing timer counting incorrectly

9 messages · Page 1 of 1 (latest)

ocean torrent
#

Hey y'all, I'm currently working on a school project (make a snake game, wow much exciting) and am stuck with some issue concerning the timer not counting the correct timestep. For example, perform an action every 1/10 second - it fails to do that.

I've asked my professor for help and he's currently unable to find the culprit after looking through my code, so thought I'd ask here.
I've checked CPU and memory utilization and afaik there's no issues. No memory leaks, no hardware issues etc.

surreal veldtBOT
#

This post has been reserved for your question.

Hey @ocean torrent! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ocean torrent
#

Happy to send code privately if anyone wants to help KissCute

#

Might also be useful to know that it works as intended using values above 500 ms,

so using 500 ms, 1000 ms (1 action every 1 second) works perfectly fine, but going lower (such as 10, 100, or 200) than that seems to break it

summer mural
#

I would recommend you to take a look at another types of game loops

#

like, calculating time between frames and make the thread sleep needed time for the next frame

ocean torrent
#

I got it fixed, no worries, turns out I drawing a grid of 800x800 every 1/10 second instead of what only covered screen