Difference between revisions of "love.keyboard.setKeyRepeat"
m (Added oldin) |
(Updated for 0.9.0 and added a new example) |
||
Line 1: | Line 1: | ||
− | {{oldin|[[0.9.0]]|090|type= | + | Enables or disables repeat keypress events. |
+ | == Function == | ||
+ | {{newin|[[0.9.0]]|090|type=variant}} | ||
+ | === Synopsis === | ||
+ | <source lang="lua"> | ||
+ | love.keyboard.setKeyRepeat( enable ) | ||
+ | </source> | ||
+ | === Arguments === | ||
+ | {{param|boolean|enable|Whether repeat keypress events should be enabled when a key is held down. The interval between repeats depends on the user's system settings.}} | ||
+ | === Returns === | ||
+ | Nothing. | ||
+ | |||
+ | == Function == | ||
+ | {{oldin|[[0.9.0]]|090|type=variant}} | ||
Enables key repeating and sets the delay and interval. | Enables key repeating and sets the delay and interval. | ||
− | |||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 11: | Line 23: | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | |||
== Examples == | == Examples == | ||
− | === | + | {{newin|[[0.9.0]]|090|type=example}} |
+ | Hold left or right to change the position. | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | love.keyboard.setKeyRepeat(true) | ||
+ | x = 50 | ||
+ | end | ||
+ | |||
+ | function love.keypressed(key, isrepeat) | ||
+ | if key == "right" then | ||
+ | x = (x + 80) % love.graphics.getWidth() | ||
+ | elseif key == "left" then | ||
+ | x = (x - 80) % love.graphics.getWidth() | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.circle("fill", x, 100) | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | ---- | ||
+ | {{oldin|[[0.9.0]]|090|type=example}} | ||
+ | Hold left or right to continue moving. | ||
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. | 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"> | ||
Line 21: | Line 57: | ||
function love.keypressed(key) | function love.keypressed(key) | ||
− | if key == "left" then x = x - 20 | + | if key == "left" then |
− | elseif key == "right" then x = x + 20 | + | x = x - 20 |
+ | elseif key == "right" then | ||
+ | x = x + 20 | ||
end | end | ||
end | end | ||
function love.draw() | function love.draw() | ||
− | love.graphics.circle("fill", x,300, 30,30) | + | love.graphics.circle("fill", x, 300, 30, 30) |
end | end | ||
</source> | </source> | ||
Line 33: | Line 71: | ||
== See Also == | == See Also == | ||
* [[parent::love.keyboard]] | * [[parent::love.keyboard]] | ||
+ | * [[love.keyboard.hasKeyRepeat]] | ||
+ | * [[love.keypressed]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description=Enables | + | {{#set:Description=Enables or disables repeat keypress events.}} |
{{#set:Since=000}} | {{#set:Since=000}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.keyboard.setKeyRepeat}} | {{i18n|love.keyboard.setKeyRepeat}} |
Revision as of 06:41, 31 August 2013
Enables or disables repeat keypress events.
Contents
Function
Available since LÖVE 0.9.0 |
This variant is not supported in earlier versions. |
Synopsis
love.keyboard.setKeyRepeat( enable )
Arguments
boolean enable
- Whether repeat keypress events should be enabled when a key is held down. The interval between repeats depends on the user's system settings.
Returns
Nothing.
Function
Removed in LÖVE 0.9.0 |
This variant is not supported in that and later versions. |
Enables key repeating and sets the delay and interval.
Synopsis
love.keyboard.setKeyRepeat( delay, interval )
Arguments
number delay
- The amount of time before repeating the key (in seconds). 0 disables key repeat.
number interval
- The amount of time between repeats (in seconds)
Returns
Nothing.
Examples
Available since LÖVE 0.9.0 |
This example is not supported in earlier versions. |
Hold left or right to change the position.
function love.load()
love.keyboard.setKeyRepeat(true)
x = 50
end
function love.keypressed(key, isrepeat)
if key == "right" then
x = (x + 80) % love.graphics.getWidth()
elseif key == "left" then
x = (x - 80) % love.graphics.getWidth()
end
end
function love.draw()
love.graphics.circle("fill", x, 100)
end
Removed in LÖVE 0.9.0 |
This example is not supported in that and later versions. |
Hold left or right to continue moving. 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(0.01, 0.2)
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