Difference between revisions of "love.timer.sleep"
(→See Also: Added PrettySince property.) |
m (Added links) |
||
Line 1: | Line 1: | ||
Pauses the current thread for the specified amount of time. | Pauses the current thread for the specified amount of time. | ||
− | {{notice|This function causes the entire thread to pause for the duration of the sleep. Graphics will not draw, input events will not trigger, code will not run, and the window will be unresponsive if you use this as "wait()" in the main thread. Use love.update or a Timer library for that instead.}} | + | {{notice|This function causes the entire thread to pause for the duration of the sleep. Graphics will not draw, input events will not trigger, code will not run, and the window will be unresponsive if you use this as "wait()" in the main thread. Use [[love.update]] or a [[love.timer|Timer library]] for that instead.}} |
== Function == | == Function == | ||
{{newin|[[0.8.0]]|080|type=behaviour}} | {{newin|[[0.8.0]]|080|type=behaviour}} |
Revision as of 14:16, 2 January 2019
Pauses the current thread for the specified amount of time.
This function causes the entire thread to pause for the duration of the sleep. Graphics will not draw, input events will not trigger, code will not run, and the window will be unresponsive if you use this as "wait()" in the main thread. Use love.update or a Timer library for that instead. |
Contents
Function
Available since LÖVE 0.8.0 |
This behaviour is not supported in earlier versions. |
Synopsis
love.timer.sleep( s )
Arguments
number s
- Seconds to sleep for.
Returns
Nothing.
Function
Removed in LÖVE 0.8.0 |
This behaviour is not supported in that and later versions. |
Synopsis
love.timer.sleep( ms )
Arguments
number ms
- Milliseconds to sleep for.
Returns
Nothing.
Examples
Use sleep to cap FPS at 30
function love.update(dt)
if dt < 1/30 then
love.timer.sleep(1/30 - dt)
end
end
More sophisticated way to cap FPS
This takes into account the time spent updating and drawing each frame.
function love.load()
min_dt = 1/30
next_time = love.timer.getTime()
end
function love.update(dt)
next_time = next_time + min_dt
--rest of function here
end
function love.draw()
--rest of function here
local cur_time = love.timer.getTime()
if next_time <= cur_time then
next_time = cur_time
return
end
love.timer.sleep(next_time - cur_time)
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