Skip to content
Crutiatix edited this page Apr 30, 2017 · 5 revisions

The first thing what you'll need to do is to copy TICuare library snippet to your code. Also, it's needed to define mouse input in metadata.

Then, you'll need to update the ticuare object in order to update the status of your elements, using ticuare.update([mouseX, mouseY, mousePress] or [active_element, btnp(n)]) and lastly, you'll want to draw your buttons using ticuare.draw(). Alternatively, you can draw individual buttons using myElement:drawSelf().

Input methods:

Mouse

-- input: mouse

-- ticuare code snippet
-- ticuare elements definitions

function TIC()
  cls(0)
  ticuare.update(mouse())
  ticuare.draw()
end

Gamepad

-- input: gamepad

-- ticuare code snippet
-- ticuare elements definitions

element1 = ticuare.element({...})
element2 = ticuare.element({...})
element3 = ticuare.element({...})

element1.onHover = function() 
  -- Actions when element is focused
end

ELEMENTS_LIST={element1, element2, element3}

ACTUAL_INDEX=1

function TIC()
  -- if left arrow pressed focus previous element in array, if out of range then go to last
  if btnp(2,1,10) then ACTUAL_INDEX = ACTUAL_INDEX > 1 and ACTUALT_INDEX - 1 or #ELEMENT_LIST end 

  -- if right arrow pressed focus next element in array, if out of range then go to first
  if btnp(3,1,10) then ACTUAL_INDEX = ACTUAL_INDEX < #ELEMENT_LIST and ACTUAL_INDEX + 1 or 1 end 
 
  cls(0)
  local focused_element = ELEMENT_LIST[ACTUAL_INDEX]
  ticuare.update(focused_element, btnp(5,1,10)) -- focused element, define click button
  ticuare.draw()
end

Gamepad with cursor

-- input: gamepad

-- ticuare code snippet
-- ticuare elements definitions

GAME_PAD={x=120,y=68,p=false} -- global var containing position and press state

function gamepad(speed) -- function simulating behavior of mouse()
  local GP=GAME_PAD
  if btn(0) then -- arrow up
    GP.y = GP.y-speed end
  if btn(1) then -- arrow down
    GP.y = GP.y+speed end
  if btn(2) then -- arrow left
    GP.x = GP.x-speed end
  if btn(3) then -- arrow right
    GP.x = GP.x+speed end
  if btn(5) then 
    GP.p = true else GP.p = false end -- click button
  GAME_PAD=GP
  return GP.x,GP.y,GP.p
end

function TIC()
  cls(0)
  ticuare.update(gamepad()) -- calling our gamepad function
  ticuare.draw()
end
Clone this wiki locally