function love.update(dt)
print(dt)
if count <= 60 then
count = count+(1*dt*100)
beat = false
else
count = 0
beat = true
end
if beat then
scalem = 0.2
end
scalem = scalem-scalem*0.1
end
I think this is possible but I can't get it. I'm very new to Love2d so I ask for help. thanks in advance
It is not possible on modern operating system because there are many processes running at the same time.
You can't ensure with 100% certainty that your function will be executed within less than a second.
Also, your question has already been asked/answered several times on here.
You can simplify things a lot by modeling beats out of the total time passed, plus using some multiplications, divisions and modulo (%) to transform that number into other useful numbers.
Here's the context:
- You need to accumulate 'dt' into some variable. Let's call it "gameTime" or something like that. It's the total time in seconds that have passed since the program started, and you accumulate it by simply doing "gameTime = gameTime + dt" inside love.update(). Note that gameTime starts as zero.
- You know how many seconds-per-beat you want to have. It's a constant that you define early in your code, let's call it BPS, for example "BPS = 2.5" (you want 2 and a half beats-per-second, AKA 150 beats per minute).
- A simple division multiplication of gameTime by BPS will give you how many beats have happened in total since the game started, that is, "totalBeats = gameTime * BPS".
With this totalBeats number you can do many fun things: after you do a math.floor() on totalBeats so you only keep the integer part of it, you can find out what's the current beat of the measure you're in (you modulo that floored totalBeats by the desired number of beats-per-measure, another constant, and this will give you a number in the range 0, 1, 2, 3...n), and you can also find out what measure you're in (you divide the totalBeats by that beats-per-measure number, giving you totalMeasures, a soft number where the whole part means how many full measures have passed, and the decimal part is the percentage of the current measure already complete).
While ivan is technically correct that the FPS of your program might oscillate as it runs, I think this will usually be imperceptible (unless the user is doing some other heavy thing in the background).
OK, I misread your original post. You are trying to sync the movement on the screen with music which is different than "keeping everything at 60fps". You may want to look into waveforms as well.
You are only counting seconds, there is no need to interact with the soundfile at this point.
That IS what dt is for after all.
But note that everything done in love.update will be out of sync by 1/60s
So if you want to have an accurate audio/video coupling, its complicated.
Meantime, thats enough: