Difference between revisions of "love.update"
(add another example) |
|||
Line 19: | Line 19: | ||
npc.think() | npc.think() | ||
end | end | ||
+ | end | ||
+ | </source> | ||
+ | Change a variable at a constant rate (3 per second). | ||
+ | <source lang="lua"> | ||
+ | var = 10 | ||
+ | rate = 3 -- change to change the rate at which the var is changed | ||
+ | function love.update(dt) | ||
+ | if love.keyboard.isDown("down") then | ||
+ | var = var + (dt * rate) | ||
+ | elseif love.keyboard.isDown("up") then | ||
+ | var = var - (dt * rate) | ||
+ | end | ||
end | end | ||
</source> | </source> |
Revision as of 05:05, 26 September 2011
Callback function used to update the state of the game every frame.
Function
Synopsis
love.update( dt )
Arguments
number dt
- Time since the last update in seconds.
Returns
Nothing.
Examples
Run a function called think inside a table called npc approximately once per second.
dtotal = 0
function love.update(dt)
dtotal = dtotal + dt
if dtotal > 1 then
dtotal = dtotal - 1
npc.think()
end
end
Change a variable at a constant rate (3 per second).
var = 10
rate = 3 -- change to change the rate at which the var is changed
function love.update(dt)
if love.keyboard.isDown("down") then
var = var + (dt * rate)
elseif love.keyboard.isDown("up") then
var = var - (dt * rate)
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