Difference between revisions of "love.keyboard.setKeyRepeat"
m (remove .lua from require) |
(Replaced example (much simpler, doesn't involve AnAL)) |
||
Line 11: | Line 11: | ||
Nothing. | Nothing. | ||
== Examples == | == Examples == | ||
− | === | + | === Hold key to continue moving left or right === |
+ | Please note that a generally better way to move an object would be to put code in [[love.update]]() which uses [[love.keyboard.isDown]]. This is just an example. | ||
<source lang="lua"> | <source lang="lua"> | ||
function love.load() | function love.load() | ||
− | + | x = 400 | |
− | + | love.keyboard.setKeyRepeat(10, 200) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | function love. | + | function love.keypressed(key) |
− | + | if key == "left" then x = x - 20 | |
− | + | elseif key == "right" then x = x + 20 | |
+ | end | ||
end | end | ||
function love.draw() | function love.draw() | ||
− | + | love.graphics.circle("fill", x,300, 30,30) | |
− | |||
end | end | ||
+ | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== See Also == | == See Also == | ||
* [[parent::love.keyboard]] | * [[parent::love.keyboard]] |
Revision as of 06:18, 2 October 2011
Enables key repeating and sets the delay and interval.
Contents
Function
Synopsis
love.keyboard.setKeyRepeat( delay, Interval )
Arguments
number delay
- The amount of time before repeating the key (in milliseconds). 0 disables key repeat.
number Interval
- The amount of time between repeats (in milliseconds)
Returns
Nothing.
Examples
Hold key to continue moving left or right
Please note that a generally better way to move an object would be to put code in love.update() which uses love.keyboard.isDown. This is just an example.
function love.load()
x = 400
love.keyboard.setKeyRepeat(10, 200)
end
function love.keypressed(key)
if key == "left" then x = x - 20
elseif key == "right" then x = x + 20
end
end
function love.draw()
love.graphics.circle("fill", x,300, 30,30)
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