Page 2 of 2
Re: Why dt?
Posted: Tue Aug 07, 2012 3:09 am
by Puzzlem00n
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.
Re: Why dt?
Posted: Tue Aug 07, 2012 3:45 am
by Inny
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
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
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.
Re: Why dt?
Posted: Tue Aug 07, 2012 9:05 am
by Nixola
I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
Re: Why dt?
Posted: Tue Aug 07, 2012 9:49 am
by T-Bone
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.
Re: Why dt?
Posted: Tue Aug 07, 2012 4:34 pm
by Puzzlem00n
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.
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.
Nixola wrote:I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
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.
)
Well, thank you to everyone for what's been said here. I've really learned a lot.
Re: Why dt?
Posted: Tue Aug 07, 2012 4:45 pm
by Nixola
The worst thing about flash games is that I like many of them, but I'm not able to play them here >.<
Re: Why dt?
Posted: Tue Aug 07, 2012 4:50 pm
by Ref
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
frame_rate = desired frames per second
love.Enable('fps', frame_rate)
and to run at maximum frame rate:
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)
Re: Why dt?
Posted: Tue Aug 07, 2012 9:48 pm
by Puzzlem00n
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
frame_rate = desired frames per second
love.Enable('fps', frame_rate)
and to run at maximum frame rate:
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)
So this basically sets it up as a fixed rate environment, like Flash? Hmm...
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.