how exactly dt works?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
raystar
Prole
Posts: 6
Joined: Mon Mar 31, 2014 3:40 pm

how exactly dt works?

Post by raystar »

hello, i can not understand how dt works, i was reading and coding some examples about dt, well, i do not clearly understand how it works, i know that dt it a measure the time it takes the processor to call back from one frame to another.

Then, if i use the game on diferent hardware, the cpu has diferent speed, that will be result on a diferent fps, if a image is on linear and constantly movement from pixel 1 to pixel 60, when i got a DeltaTime value of 0.016 it is aprox 60fps or 1 pixel movement-factor (the image is display 60 times/second, 1 image per 1 pixel); but if i got a 0.05 DeltaTime value, it is a 20fps or 3 pixel movement-factor(the image is display 20 times/second, 1 image every 3 pixels).

Questions:
DeltaTime 0.05 vrs DeltaTime 0.02, the game with DeltaTime 0.05, do the game have lag? or is not smooth motion such as 0.02 DeltaTime Game?

will the game move the image the same distance(60 pixels/second) does not matter the lag?(trying play a game that normaly is 60 fps)

what happend if i have a pc with better DeltaTime?
Attachments
turorial.love
Hamster ball tutorial, speed is not such as in tutorial.-
(4.52 KiB) Downloaded 112 times
Last edited by raystar on Thu Apr 10, 2014 5:08 pm, edited 1 time in total.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: how exactly dt works?

Post by Jeeper »

DT is the time between 2 frames.

If you set a player to move at a speed of 1 pixel, he will move 1 pixel every frame. This means that if you have 2 fps, you will move twice as fast as someone with 1fps.

If you set a players speed to 1 * dt it will run equally fast on both the computer with 1 fps and the computer with 2 fps.

On 1 fps the dt would be replaced by 1. As it took 1 second to swap frames. This means that the player will move 1 * 1 = 1 frames per second.

On 2 fps the dt would be replaced by 0.5. As it took 0.5 second to swap frames. This means that the player will move 1 * 0.5 = 0.5 frames per second. But as this player gets twice as many frames as the first example, you will still move at a speed of 1.
User avatar
raystar
Prole
Posts: 6
Joined: Mon Mar 31, 2014 3:40 pm

Re: how exactly dt works?

Post by raystar »

Jeeper wrote:DT is the time between 2 frames.

If you set a player to move at a speed of 1 pixel, he will move 1 pixel every frame. This means that if you have 2 fps, you will move twice as fast as someone with 1fps.

If you set a players speed to 1 * dt it will run equally fast on both the computer with 1 fps and the computer with 2 fps.

On 1 fps the dt would be replaced by 1. As it took 1 second to swap frames. This means that the player will move 1 * 1 = 1 frames per second.

On 2 fps the dt would be replaced by 0.5. As it took 0.5 second to swap frames. This means that the player will move 1 * 0.5 = 0.5 frames per second. But as this player gets twice as many frames as the first example, you will still move at a speed of 1.
Thanks for take your time to answer my question.

Well, i think that i already understand dt.
but if i want set the game to 60 fps, how do i do it? cause the speed it´s constantly but the fps does not.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: how exactly dt works?

Post by Jeeper »

raystar wrote:
Jeeper wrote:DT is the time between 2 frames.

If you set a player to move at a speed of 1 pixel, he will move 1 pixel every frame. This means that if you have 2 fps, you will move twice as fast as someone with 1fps.

If you set a players speed to 1 * dt it will run equally fast on both the computer with 1 fps and the computer with 2 fps.

On 1 fps the dt would be replaced by 1. As it took 1 second to swap frames. This means that the player will move 1 * 1 = 1 frames per second.

On 2 fps the dt would be replaced by 0.5. As it took 0.5 second to swap frames. This means that the player will move 1 * 0.5 = 0.5 frames per second. But as this player gets twice as many frames as the first example, you will still move at a speed of 1.
Thanks for take your time to answer my question.

Well, i think that i already understand dt.
but if i want set the game to 60 fps, how do i do it? cause the speed it´s constantly but the fps does not.
First of all, why would you want to limit the FPS? There are absolutely no good reasons that I could think of. Enabling Vsync will cap your frame rate at 60.

You do not need the FPS to be constant, when the fps goes down,the dt value goes up. When the fps goes up the dt goes down. So it balances it out so that you will have the same speed regardless of FPS.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: how exactly dt works?

Post by substitute541 »

Like Jeeper said, limiting frames isn't all that useful.

It would be useful however, to limit frame rates if your fps goes too low (say, 6 FPS.) If that happens, you can do three things:
  • Ignore FPS drop (this would make dt large, and thus may make your frame-by-frame calculations inaccurate.)
  • Limit lower bound of FPS using math.min(dt, 0.016667) . This would slow down your game once it reaches low FPS though.
  • Do more updates per frame.
If you REALLY want to lock framerate to 60 FPS, you can do something like this:

Code: Select all

function love.load()
	cur_time = 0

	-- other code
end

function love.update(dt)
	cur_time = cur_time + dt
	dt = 0.016667
	while cur_time > 0 do
		-- update code here...

		-- on the very bottom
		cur_time = cur_time - dt
	end
end
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
raystar
Prole
Posts: 6
Joined: Mon Mar 31, 2014 3:40 pm

Re: how exactly dt works?

Post by raystar »

Jeeper wrote: First of all, why would you want to limit the FPS? There are absolutely no good reasons that I could think of. Enabling Vsync will cap your frame rate at 60.

You do not need the FPS to be constant, when the fps goes down,the dt value goes up. When the fps goes up the dt goes down. So it balances it out so that you will have the same speed regardless of FPS.
well, in my case, i prefer set a standard frame rate in a super PC and a standard PC. and of course i really think that not all have a monitor that works faster than 120 hz, the most popular monitors works on 85 hz, if your game works faster than 125% available hz a horrible wake is follow your images(101% the wake is there but do not realize).
that is my reason. :)
substitute541 wrote:Like Jeeper said, limiting frames isn't all that useful.

It would be useful however, to limit frame rates if your fps goes too low (say, 6 FPS.) If that happens, you can do three things:
  • Ignore FPS drop (this would make dt large, and thus may make your frame-by-frame calculations inaccurate.)
  • Limit lower bound of FPS using math.min(dt, 0.016667) . This would slow down your game once it reaches low FPS though.
  • Do more updates per frame.
If you REALLY want to lock framerate to 60 FPS, you can do something like this:

Code: Select all

function love.load()
	cur_time = 0

	-- other code
end

function love.update(dt)
	cur_time = cur_time + dt
	dt = 0.016667
	while cur_time > 0 do
		-- update code here...

		-- on the very bottom
		cur_time = cur_time - dt
	end
end
wow, i think that it will work fine, i will try and see what happend.
thanks
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests