Difference between revisions of "love.keyboard.setKeyRepeat"

Line 11: Line 11:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
=== Quit on hitting escape ===
+
=== Press key to continue moving left or right ===
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()

Revision as of 09:17, 10 May 2010

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 milliseconds). 0 disables key repeat.
number Interval
The amount of time between repeats (in milliseconds)

Returns

Nothing.

Examples

Press key to continue moving left or right

function love.load()
	require("AnAL.lua")
   -- Load the animation source.
	imgl = love.graphics.newImage("walkl.png")
	imgr = love.graphics.newImage("walkr.png")
   -- Create animation.

   anim = newAnimation(imgsl, 32, 48, 0.1, 0)
   animX = 100
   animY = 100
   --  Interval value = Animation's Delay time * The number of Animation's frame 
   love.keyboard.setKeyRepeat(10, 200)
end

function love.update(dt)
   -- Updates the animation. (Enables frame changes)
   anim:update(dt)
end

function love.draw()
   -- Draw the animation at (100, 100).
   anim:draw(animX , animY)
end

function love.keypressed(key,unicode)
	if key == "left" then
		anim = newAnimation(imgl,32,48,0.1,0)
		anim:setMode ("once")
		animX = animX - 10
	elseif key == "right" then
		anim = newAnimation(imgr, 32, 48, 0.1, 0)
		animX = animX + 10
		anim:setMode ("once")
	end
end

See Also