Question about timers in gdevelop

Are timers in gdevelop working with timedelta?
For example, if a game gets a frame drop, does that cause the timer to slow down (gets offset as compared to the real time) or does it continue to show the correct time (automatically takes into consideration frame drops/lag)?

I am asking about this, because I am trying to make a rhytm game and wondering wheter I need to do something similar to this: … ted/14146/

in order to get a timer that automatically corrects itself when there are frame drops. Or does the timer in gdevelop already do that? In which case, setting up an elaborate timer like the one in the link would be kind of a waste of time (no pun intended).

1 Like

Timers are obviously using the real time and will not get affected by a fps drop.

But it does :smiley: I cant get it to stay in sync with the music.

Ok here is the challenge:
unrar (24.9 KB)
Set the sound file “test120beat.wav” to loop from the start of the frame.
It is using 120 BPM

now make the click.wav file play in sync with it by using code. On every second beat, the click should play exactly at the same time!

Run this in native, with the debugger on.
I get massive offsets when the framerate is not consistent.

How do I tell it to stay in sync even when the frame rate is not consistent?

1 Like

What is affected by the FPS drop, it’s the time between the timer going greater than X seconds and the timer being reset.

is there a way to keep the clicks in sync with the beats loop, by using code obviously.

In this case I guess I could use the timer, but I can’t reset it.

So I guess that this is where a feature suggestion “repeat every X seconds” could be useful!

You can let the timer run, and then test each seconds. i’ll post an example that you can test (I can’t create FPS drop myself).
Like this :
Projet.gdg (7.26 KB)
(Adapt BEAT_INTERVAL and the sound files).

1 Like

OK! I was able to keep it fairly stable by using an overall timer and a gradually increasing value:

The variable beat increases by the increment of seconds that are between each beat (based on BPM value) on each beat.

Now I need to figure out how to get that value!
In for example I have 120BPM (beats per minute), then that makes 120/60=2 BPS (beats per second), which makes
2/1000 = 0.002 BPMS (beats per milisecond)

Now how do I get the time (in milliseconds) between two beats? I need help with the math :smiley:

I see now in your example :

It does it in a similar fashion but uses two variables.
I guess now all thats left is to figure out a formula to get the correct beat interval from a BPM value.

The reason I need to use a BPM value is that I decided to load an xml file from hydrogen:

in order to read my beat patterns in the game

Actually, you know what? We’ve been going the wrong way at it from the start!

When the game lags, the music in it lags - but the timer continues running real time - which leads to timing offset.

So Now really, I need the opposite - a timer that lags with the game.

This is so difficult to achieve!

I am not completely sure a rhytm game can be made in gdevelop!

If you play the music using the music action (for ogg) instead of the sound action, the music will not lag because it will be read from another thread. :wink:

if its set to loop, would it introduce offset (lag) ?

Ok thinking more about it, the problem really is with the sound system. When the game lags, the music that is played also lags. This introduces a time offset between the game’s internal clock (timer) and the actual song being played. A single offset breaks the entire game onward- because it is based on timing.

4ian is working on a better sound system: … rformances

I hope it helps with the problem.

Basically I see two ways around it:
I can do one of the two:

  • get a timer that lags with the game - equal to the lag of the music - so when music lags,timer lags too. (both timer and music lag)
  • get a way to readjust the music, so when a lag is introduced, the game readjusts the timing of the music to be correct with the game’s timer
    (music lags–>music readjusts itself - skips ahead to make up for the lag so its back to the same value as the timer)

The music that is played has a timer of its own that just as any other timer in gdevelop does not get affected by lags. So when there is a lag, instead of pausing/slowing the music, the game skips to the appropriate time of the song. Automatically correcting the time of the song.

-do it manualy - New condition to check if the game framerate is too low and a new action to set the music being played time to a new value (in this case - set it to the overal timer clock we have running from the beginning of the frame)

  • or do it internally - automatically.

this is important to get right before doing any further work. I will try to implement a laggy timerwith the event system now

EDIT: After further look into this, I need to be able to get the game’s current framerate in order to be able to implement a laggy timer with this logic:

in place of the “60” I need to put an expression command that gets the game’s current FPS. Can this be done in gdevelop?

Ok after trying this :

a laggy timer seems to make things even worse with the offset. :unamused:
i am not sure how to keep things in sync when lag is introduced any more

Just discovered that gdevelop , being awesome as it is, has a way of checking the current time of a channel!

So I added a line to check if there is an offset that is bigger than 0.25. If so, readjust the time of the music playing in channel 0 to the time of the overalTime timer.

This way it will stay in sync when there is lag, but there will be an ugly skip in the song if there is offset.
A better solution would be to have the timer lag with the song lag. I tried to do that with the previous post formula and got horrible results.
I am actually getting a new idea! Why not set the timer to the song offset!

That way the lag happens to the song - then instead of the song skipping ahead - the timer readjusts itself.
Since there is no action to adjust the value of a timer, I have to store the timer in a variable. This probably doesnt work, because the variable is overwritten by the other action which sets it to the overalTimer timer. :unamused:

Or even a cleaner solution would be instead of using a stupid timer, just use the song offset!

but for some reason this stops working after a while. Probably because after the first loop, the song’s offset is lower than the nextBeat value. Unfortunatelly there is no way to check how many times a song has looped.

Why is the sound performance so bad in html5 and ok in native?

Ok the best solution to me seems to be in using the song’s offset rather than a timer. The problem with that is that gdevelop does not show it in milliseconds and skips evaluating the time between seconds


I need to be able to evaluate in quaters of a second at least:

I having been developing a rhythm game for android in gdevelop for 6 months now. I can assure you everyone making rhythm games is over complicating it. My game is set up for 360p resolution. 360 x 640. My graphics are all PNG high quality with transparency. My songs are all MP3 and my sound effects are all wavs. My arrows come from the top and are laid out manually in the scene at 500px force on y value. I have one song that’s even over 1100 notes. And it runs perfectly fine with no lag and matches the song how I built it. I’ve had a few people say I have to sync the video with the audio and other crap but it’s not true. As long as the resolution is low enough for the phone running it to play it there is no video lag. and the game works fine. It doesn’t look bad at 360p either. And it runs on a phone I have that is like 15 years old. Gdevelop is an excellent program. I built an Online leaderboard in it. I had to test my game over 1000 times to get it working right. For some reason the timing is off when I test it, but it’s fine on android. I figured it out by testing over and over. But the song and notes stay in sync the whole time now. All you have to do is create a blank hit box spanning above your target zone about 2000 pixels. a different blank box in the target area, and a blank line underneath the target area for another hit test. Buttons have to me set up properly. And when you do the hit test on push on a button you have to use the code, pick the object that is closest to (whatever pixels are closest to the target area) once I did that it was able to only focus on the arrows that where in the target area. You need a script for on push in the outer target area for a miss, and a script on push in the target area for a successful hit. When the user gets a successful note, the animation in the arrows change to a different animation with no hit test box. called “clear” So if you hit it on time it can’t collide with the box below the target area for a miss. and if you press the button too early it hit tests on the outer area box that is also a miss. I have 14 different styles of buttons and arrows, and it doesn’t slow the game down at all. Each arrow has 14 different animations inside of it and some songs are over 1000 notes. so 14000 animations in one object times 4 in one scene. And it doesn’t lag at all. My frame rate is 26. Once you lower the resolution enough you would be surprised at how well gdevelop works.

I figured I’d explain this to people because I see everyone struggling trying to make the notes come at specific times. Don’t do that! Just lay them out above at a certain speed. Guitar hero does it that way. And if the user misses, reset the note streak variable etc. etc. And make the volume on the song drop 70 percent for a few seconds or until the user hits a successful note again.

Rhythm Retro will be available in a month or two on the play store. Thanks.