Yup, I think I've got my head around it.
It's a funny thing, I've been pretty good with programming for a little less than a year now (and been trying to be good even longer) yet there seems to always be something new coming up that I don't know. I've been able to code an (albeit glitchy) rudimentary platformer engine in a day for months, yet I'm only getting this now.
Of course, I suppose I never really tried to learn the back-end stuff, anyway. I've been focusing on the code I have to write. If you asked me to explain how LÖVE works internally, I'd tell you I never really looked in to it. Maybe I should try and get a better understanding of this stuff.
I guess the chosen framerate works for Flash because trying to take advantage of as much framerate as possible would just slow it back down... Such is the way of browser games.
Why dt? [QUESTIONS ANSWERED, RESUME YOUR DAILY LIVES]
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Why dt?
I LÖVE, therefore I am.
Re: Why dt?
I meant to say that a more complex timer could be created. Without having to overwrite love.run, you can do this in love.update
This clock has a fixed 30fps rate, and a single frameskip in order to catchup a bit. Since no logic should be happening in love.draw, it'll end up redrawing the same static frame over and over. This isn't really a problem, unless you're doing some complex drawing. Maybe look into canvases if you are.
Code: Select all
local clock = 0
local rate = 1.0 / 30
local skip = rate * 2
function love.update(dt)
if dt > skip then dt = skip end -- discard system hiccups
clock = clock + dt
while clock > rate do
clock = clock - rate
MyGame:update() -- your fixed rate logic here
end
end
Re: Why dt?
I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Why dt?
If it ain't broke, don't fix it. The dt way works great on all platforms on both slow and fast computers. And it's really simple to use.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Why dt?
Like I said, I had sort of anticipated from the beginning that there was something I wasn't getting, and for these reason, I never called for fixing it, and now I know.T-Bone wrote:If it ain't broke, don't fix it. The dt way works great on all platforms on both slow and fast computers. And it's really simple to use.
That's quite a shame. A lot of the best games I've ever played were in flash. (I have strange tastes. Call me hipster. )Nixola wrote:I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
Well, thank you to everyone for what's been said here. I've really learned a lot.
I LÖVE, therefore I am.
Re: Why dt?
The worst thing about flash games is that I like many of them, but I'm not able to play them here >.<
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Why dt?
Now that I finally figured out (with help) how to load a modified love.run, I can now easily set a fixed frame rate from within my script. Sure, if drawing takes longer than the frame rate, the script will run without any additional delay.
To use, all that is needed is to add:
and anywhere in your script you can change the frame rate (on the fly) by:
and to run at maximum frame rate:
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)
To use, all that is needed is to add:
Code: Select all
require 'love_run'
Code: Select all
frame_rate = desired frames per second
love.Enable('fps', frame_rate)
Code: Select all
love.Disable('fps')
- Attachments
-
- love_run_mod.love
- bastardize love.run example
- (1.6 KiB) Downloaded 96 times
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Why dt?
So this basically sets it up as a fixed rate environment, like Flash? Hmm...Ref wrote:Now that I finally figured out (with help) how to load a modified love.run, I can now easily set a fixed frame rate from within my script. Sure, if drawing takes longer than the frame rate, the script will run without any additional delay.
To use, all that is needed is to add:and anywhere in your script you can change the frame rate (on the fly) by:Code: Select all
require 'love_run'
and to run at maximum frame rate:Code: Select all
frame_rate = desired frames per second love.Enable('fps', frame_rate)
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)Code: Select all
love.Disable('fps')
I'm getting some mixed responses here. I sort of thought it was over after everyone explained why dt is a better solution... Now I'm getting ways to implement fixed rate. To be clear, I don't need this code. It would be fun to experiment with... But I can't see myself needing to modify love.run. There is a small chance I may want to use Inny's second code example some day, but I don't even really need it, either.
So, despite your work being very, very cool, I can't guarantee it will be put to use. I'm very sorry if you thought I was intent on making a fixed rate game, and you thought I wanted someone to make this for me. I just wanted someone to explain things.
I LÖVE, therefore I am.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest