Difference between revisions of "love.keyboard.setKeyRepeat"

m (1 revision: Importing from potato (again).)
Line 1: Line 1:
 
 
Enables key repeating and sets the delay and interval.
 
Enables key repeating and sets the delay and interval.
 
== Function ==
 
== Function ==
Line 11: Line 10:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
== Examples ==
 +
=== Quit on hitting escape ===
 +
<source lang="lua">
 +
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
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::love.keyboard]]
 
* [[parent::love.keyboard]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Enables key repeating and sets the delay and interval.}}
 
{{#set:Description=Enables key repeating and sets the delay and interval.}}

Revision as of 09:14, 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

Quit on hitting escape

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