-
-
Notifications
You must be signed in to change notification settings - Fork 490
TimotheeGreg edited this page Oct 16, 2023
·
27 revisions
btn(id) -> is_pressed
-
btn() -> GAMEPADS data
(see RAM)
-
id : id (0..31) of the key we want to interrogate (see the key map for reference or type
help buttons
in console).
- is_pressed : button is pressed (true/false)
- GAMEPADS data : 32-bit value that represents current state of all GAMEPAD button inputs
This function allows you to read the status of TIC's controller buttons. It returns true
if the button with the supplied id is currently in the pressed state and remains true
for as long as the button is held down. To see if a button was just pressed, use btnp instead.
Set the metadata input
tag to gamepad
to display only the on-screen gamepad on Android devices and hide the keyboard.
The following example displays the state of all buttons during each frame:
--Key Test Project
--By Rain_Effect,pixelbath
local ox=70
local oy=15
local btnLabel={"Up","Down","Left","Right","Btn A","Btn B","Btn X","Btn Y"}
function printBtnLabels(x, y, headingText)
print(headingText,x,y,8)
for i=1,8 do
print(btnLabel[i],x,y+i*10,12)
end
end
function printInputState(x, y, headingText, startIdx)
print(headingText,x,y,8)
for i=1,8 do
if btn(i-1+startIdx) then
print("On",x,y+i*10,6)
else
print("Off",x-3,y+i*10,1)
end
end
end
function TIC()
cls(0)
print("Key Test Project",ox,oy,12)
printBtnLabels(ox-30, oy+15, "Btn")
printInputState(ox+20, oy+15, "1P", 0)
printInputState(ox+50, oy+15, "2P", 8)
printInputState(ox+80, oy+15, "3P", 16)
printInputState(ox+110, oy+15, "4P", 24)
end
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)