love.keyboard.setKeyRepeat
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
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")
imgsl = love.graphics.newImage("stopl.png")
imgsr = love.graphics.newImage("stopr.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
-- 100 ms * 2 frame = 200 ms (Interval)
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