|
Okay, so you've gotten through the typical "Hello,
World!" example and now you want to learn how to do something that you
will actually use all the time. Fine, let's take a look at how
the PA_Lib handles input from the pad (or buttons).
|
// Includes #include <PA9.h> // Include for PA_Lib
#include <String> // Used for C++ style strings
// Function: main() int main(int argc, char ** argv) { // Variables std::string Button = "No ";
PA_Init(); // Initializes PA_Lib PA_InitVBL(); // Initializes a standard VBL
// PA_LoadSplash(); // PA_Lib splash screen
PA_InitText(1, 0); // Text system for top screen PA_InitText(0, 0); // Text system for on botton screen
PA_SetTextCol(1, 31, 31, 31); // 1 = botton screen, 0,0,0 = R,G,B PA_SetTextCol(0, 0, 31, 0); // 0 = top screen, 0,0,0 = R,G,B
PA_OutputSimpleText(1, 0, 0, "Press Any Button"); // 1 = top screen, 0 = Tile X, 0 = Tile Y
// Infinite loop to keep the program running while (1) { // Determine which button was pressed if (Pad.Held.Start) { Button = " Start"; } else if (Pad.Held.Select) { Button = "Select"; } else if (Pad.Held.A) { Button = " A"; } else if (Pad.Held.B) { Button = " B"; } else if (Pad.Held.X) { Button = " X"; } else if (Pad.Held.Y) { Button = " Y"; } else if (Pad.Held.L) { Button = " L"; } else if (Pad.Held.R) { Button = " R"; } else if (Pad.Held.Up) { Button = " Up"; } else if (Pad.Held.Down) { Button = " Down"; } else if (Pad.Held.Left) { Button = " Left"; } else if (Pad.Held.Right) { Button = " Right"; } else { Button = " "; }
PA_OutputText(0, 0, 12, "%s button pressed.",Button.c_str()); // 0 = Bottom Screen, 0 = Tile X, 12 = Tile Y
PA_WaitForVBL(); // Wait for VBL to complete }
return 0; } // End of main()
|
|
Code
Explanation
As you can see, reading input from the pad is quite simple.
Hopefully you know something about the C++ STL String class. If not, grab yourself a book!
Pad.Held.<button>
This is how you can find out what button is pressed. You can also
use Pad.Newpress.<button> and Pad.Released.<button> to find
out what button was just pressed or released, but don't worry about
that for now.
|