Difference between revisions of "Tactile"

(Adding keyword.)
(One intermediate revision by one other user not shown)
Line 2: Line 2:
  
 
<source lang="lua">
 
<source lang="lua">
function love.load()
+
Control = {
  tactile = require 'tactile'
+
   Horizontal = tactile.newControl()
 
+
    :addAxis(tactile.gamepadAxis(1, 'leftx'))
  --button detectors
+
     :addButtonPair(tactile.keys 'left', tactile.keys 'right'),
   keyboardLeft  = tactile.key('left')
+
   Fire = tactile.newControl()
  keyboardRight = tactile.key('right')
+
    :addButton(tactile.gamepadButtons(1, 'a'))
  keyboardX     = tactile.key('x')
+
    :addButton(tactile.keys 'x')
  gamepadA      = tactile.gamepadButton('a', 1) --the second argument is controller number, in case you're wondering
+
}
 
 
  --axis detectors
 
   keyboardXAxis = tactile.binaryAxis(keyboardLeft, keyboardRight)
 
  gamepadXAxis  = tactile.analogStick('leftx', 1)
 
 
 
  --controls
 
  horizontal    = tactile.addAxis(keyboardXAxis, gamepadXAxis)
 
  shoot        = tactile.addButton(keyboardX, gamepadA)
 
end
 
  
 
function love.update(dt)
 
function love.update(dt)
   --you have to update buttons, sorry for the extra step :(
+
   Control.Horizontal:update()
  shoot:update()
+
   Control.Fire:update()
 
 
  --movement
 
   player.x = player.x + player.speed * horizontal:getValue() * dt
 
  
   --shooting
+
   player.x = player.x + player.speed * Control.Horizontal() * dt
   if shoot:pressed() then
+
   if Control.Fire:isDown() then
 
     player:shoot()
 
     player:shoot()
 
   end
 
   end
Line 35: Line 23:
  
 
[[Category:Libraries]]
 
[[Category:Libraries]]
{{#set:LOVE Version=0.9.2}}
+
{{#set:LOVE Version=0.10.x}}
 
{{#set:Description=A flexible and nice input library.}}
 
{{#set:Description=A flexible and nice input library.}}
 +
{{#set:Keyword=Input}}

Revision as of 11:08, 18 January 2017

Tactile is a flexible and straightforward input library for LÖVE to help you manage multiple input sources. Get the code on GitHub.

Control = {
  Horizontal = tactile.newControl()
    :addAxis(tactile.gamepadAxis(1, 'leftx'))
    :addButtonPair(tactile.keys 'left', tactile.keys 'right'),
  Fire = tactile.newControl()
    :addButton(tactile.gamepadButtons(1, 'a'))
    :addButton(tactile.keys 'x')
}

function love.update(dt)
  Control.Horizontal:update()
  Control.Fire:update()

  player.x = player.x + player.speed * Control.Horizontal() * dt
  if Control.Fire:isDown() then
    player:shoot()
  end
end