DSLuaではボタンの取得を簡単にサポートしています。
Pads.○○()
対応するボタンが押されている場合には真を、押されていない場合には偽を返します。
記述方法 | 対応するボタン |
A() | Aボタン |
B() | Bボタン |
X() | Xボタン |
Y() | Yボタン |
R() | Rボタン |
L() | Lボタン |
Up() | 十字キーの上 |
Down() | 十字キーの下 |
Right() | 十字キーの右 |
Left() | 十字キーの左 |
Start() | STARTボタン |
Select() | SELECTボタン |
AnyKey() | 全てのボタンに反応 |
サンプルコード
以下のプログラムは、取得したボタンを画面に表示するプログラムになります。
タッチスクリーン以外の全てのボタンに反応し、STARTボタンが押された時に終了します。
-- 上画面の初期化 SCREEN_TOP = 1 BGTopText = Screen.LoadTextBG() Screen.Initialize( SCREEN_TOP, BGTopText )
-- 文字カラーを青色に BGTopText:SetColor(6)
-- 初期画面(何かが押されるまで待機) BGTopText:PrintXY(5, 12, "Let's Start!") DSLua.WaitForAnyKey() BGTopText:Clear()
-- 無限ループ(スタートを押すと終了) while ( 1 ) do
if Pads.A() then BGTopText:PrintXY(5, 12, "A") DSLua.WaitForAnyKey() end
if Pads.B() then BGTopText:PrintXY(5, 12, "B") DSLua.WaitForAnyKey() end
if Pads.X() then BGTopText:PrintXY(5, 12, "X") DSLua.WaitForAnyKey() end
if Pads.Y() then BGTopText:PrintXY(5, 12, "Y") DSLua.WaitForAnyKey() end
if Pads.L() then BGTopText:PrintXY(5, 12, "L") DSLua.WaitForAnyKey() end
if Pads.R() then BGTopText:PrintXY(5, 12, "R") DSLua.WaitForAnyKey() end
if Pads.Up() then BGTopText:PrintXY(5, 12, "UP") DSLua.WaitForAnyKey() end
if Pads.Down() then BGTopText:PrintXY(5, 12, "DOWN") DSLua.WaitForAnyKey() end
if Pads.Left() then BGTopText:PrintXY(5, 12, "LEFT") DSLua.WaitForAnyKey() end
if Pads.Right() then BGTopText:PrintXY(5, 12, "RIGHT") DSLua.WaitForAnyKey() end
if Pads.Select() then BGTopText:PrintXY(5, 12, "SELECT") DSLua.WaitForAnyKey() end
if Pads.Start() then BGTopText:PrintXY(5, 12, "START") break end
BGTopText:Clear() end