Difference between revisions of "love.keyboard.setKeyRepeat"

m
m (updated for 0.8.0 (setKeyRepeat is in seconds now))
Line 6: Line 6:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|delay|The amount of time before repeating the key (in milliseconds). 0 disables key repeat.}}
+
{{param|number|delay|The amount of time before repeating the key (in seconds). 0 disables key repeat.}}
{{param|number|interval|The amount of time between repeats (in milliseconds)}}
+
{{param|number|interval|The amount of time between repeats (in seconds)}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 16: Line 16:
 
function love.load()
 
function love.load()
 
x = 400
 
x = 400
love.keyboard.setKeyRepeat(10, 200)
+
love.keyboard.setKeyRepeat(0.01, 0.2)
 
end
 
end
  

Revision as of 00:07, 11 April 2012

Enables key repeating and sets the delay and interval.

Function

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

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(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