I am new to love2d and I was making a simple clicker game and needed a timer for that so I made a variable in the game table named "t" and placed it in the update function:
function love.update(dt)
game.t = game.t + 1
end
but I realized that the t variable will be added with 1 with the frame rate so on fast computers the timer will run faster so how can I fix that ?
I hope you guys will help me fix this
How to make a timer ? [Answered]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to make a timer ? [Answered]
Last edited by zalander on Wed Jan 25, 2023 4:16 pm, edited 1 time in total.
Using LOVE to make everything except games
Code: Select all
astring = "pog"
print(astring)
--pog
Re: How to make a timer ?
https://github.com/rxi/tick ?
https://github.com/love2d-community/awesome-love2d
Search for the keyword "timer"
Maybe you find something that works
https://github.com/love2d-community/awesome-love2d
Search for the keyword "timer"
Maybe you find something that works
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: How to make a timer ?
The simplest solution to your timer issue is incrementing by delta time, instead of by a fixed value:
Of course, because this involves floating points, you can't check for exact equivalence ("game.t == 101"), and instead need to use greater/less than operators (<, >, <=, >=). Another issue is that if the delta time between frames suddenly jumps up or down, you might miss any timer "ranges" you were seeking to capture (eq. you're waiting for timer to be between 100 and 105. However, a lag spike causes the timer to jump from 98 to 107), requiring extra care.
If you'd like to use integer timers, then you'd have to implement something like fixed timestep in your code. This library can do it for you.
Code: Select all
function love.update(dt)
game.t = game.t + dt
end
If you'd like to use integer timers, then you'd have to implement something like fixed timestep in your code. This library can do it for you.
Re: How to make a timer ?
Thanks for the help !
Its fixed now
Its fixed now
Using LOVE to make everything except games
Code: Select all
astring = "pog"
print(astring)
--pog
Who is online
Users browsing this forum: No registered users and 6 guests