mirror of https://github.com/mgba-emu/mgba.git
Res: Add example gamepad demo
This commit is contained in:
parent
0dd7cfd44a
commit
a62a3eb811
|
@ -0,0 +1,32 @@
|
||||||
|
inputBuffer = console:createBuffer("Input")
|
||||||
|
|
||||||
|
function readPad()
|
||||||
|
inputBuffer:clear()
|
||||||
|
|
||||||
|
if not input.activeGamepad then
|
||||||
|
inputBuffer:print("No gamepad detected\n")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local gamepad = input.activeGamepad
|
||||||
|
local axes = gamepad.axes
|
||||||
|
local buttons = gamepad.buttons
|
||||||
|
local hats = gamepad.hats
|
||||||
|
|
||||||
|
inputBuffer:print(string.format("%i buttons, %i axes, %i hats\n", #buttons, #axes, #hats))
|
||||||
|
|
||||||
|
local sbuttons = {}
|
||||||
|
for k, v in ipairs(buttons) do
|
||||||
|
if v then
|
||||||
|
sbuttons[k] = "down"
|
||||||
|
else
|
||||||
|
sbuttons[k] = " up"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
inputBuffer:print(string.format("Buttons: %s\n", table.concat(sbuttons, ", ")))
|
||||||
|
inputBuffer:print(string.format("Axes: %s\n", table.concat(axes, ", ")))
|
||||||
|
inputBuffer:print(string.format("Hats: %s\n", table.concat(hats, ", ")))
|
||||||
|
end
|
||||||
|
|
||||||
|
callbacks:add("frame", readPad)
|
Loading…
Reference in New Issue