Nintendo DS


Introduction


Version History

Day 1
Environment Setup

Links

WiFiMe

PA_Lib

Linux

Emulators

Downloads

Demos




NDS Magic Key MK2/MK3

   Hosted by
FrogNet


Document made with Nvu

 

Nintendo DS Development Tutorial :: Day 5 :: Input - Stylus

 

Okay, so you learned how to get input from the buttons on Day 2, now let's learn how to get input from the stylus, or touch screen.   Heck, the touch screen is what sets the DS apart from other video game systems, so we have to find a way to use it in our game/application!

 

// Includes
#include <PA9.h> // Include for PA_Lib
// Function: main()
int main(int argc, char ** argv)
{
PA_Init();
PA_InitVBL();

//PA_LoadSplash();

PA_InitText(1, 0);
PA_InitText(0, 0);

PA_SetTextCol(1, 31, 31, 31);
PA_SetTextCol(0, 0, 0, 31);

PA_OutputSimpleText(1, 0, 0, "Test Out The Stylus");

// Infinite loop to keep the program running
while (1)
{
if (Stylus.Held) { // Stylus is touching the screen
PA_OutputText(0, 0, 5, "Stylys X Coordinate: %d", Stylus.X);
PA_OutputText(0, 0, 7, "Stylus Y Coordinate: %d", Stylus.Y);
} else { // Stylus is not touching the screen
PA_OutputText(0, 0, 5, "Touch the screen ");
PA_OutputText(0, 0, 7, " ");
}

PA_WaitForVBL();
}

return 0;
} // End of main()

Code Explanation

There isn't too much to explain about today's tutorial - it's just so easy to get input from the stylus.  The main thing you'll want to do is check Stylus.Held and get its X & Y coordinates from Stylus.X and Stylus.Y.

NOTE: This demo will not currently work on any of the emulators.   It will only work on a real DS.

 

Download

Day5_Input_Stylus

 

Screenshot

Day5_Input_Stylus

 

Last Update: 10/31/2005

 

Google
 
Web aaronrogers.com/nintendods

 

<<

HOME

>>