Difference between revisions of "dt"
m |
m |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | dt is the most common shorthand for delta-time, which is usually passed through [[love.update]] to represent the amount of time which has passed since it was last called. It is in seconds, but because of the speed of modern processors is usually smaller than 1 | + | dt is the most common shorthand for delta-time, which is usually passed through [[love.update]] to represent the amount of time which has passed since it was last called. It is in seconds, but because of the speed of modern processors is usually smaller than 1 values like 0.01 are common. |
== Examples == | == Examples == | ||
Line 8: | Line 8: | ||
function love.update(dt) | function love.update(dt) | ||
x = x + dt | x = x + dt | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | |||
+ | === Change a position x at a fixed speed while a key is held down === | ||
+ | <source lang="lua"> | ||
+ | x = 0 | ||
+ | speed = 32 | ||
+ | function love.update(dt) | ||
+ | if love.keyboard.isDown("right") then | ||
+ | x = x + (speed * dt) -- x will increase by 32 for every second right is held down | ||
+ | elseif love.keyboard.isDown("left") then | ||
+ | x = x - (speed * dt) | ||
+ | end | ||
end | end | ||
</source> | </source> | ||
Line 15: | Line 29: | ||
* [[love.update]] | * [[love.update]] | ||
* [[love.timer.getDelta]] | * [[love.timer.getDelta]] | ||
+ | |||
+ | |||
+ | == Other Languages == | ||
+ | {{i18n|dt}} |
Latest revision as of 03:05, 29 May 2017
dt is the most common shorthand for delta-time, which is usually passed through love.update to represent the amount of time which has passed since it was last called. It is in seconds, but because of the speed of modern processors is usually smaller than 1 values like 0.01 are common.
Contents
Examples
Increase a variable x by 1 every second
x = 0
function love.update(dt)
x = x + dt
end
Change a position x at a fixed speed while a key is held down
x = 0
speed = 32
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt) -- x will increase by 32 for every second right is held down
elseif love.keyboard.isDown("left") then
x = x - (speed * dt)
end
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info