From d3444080c31f10871ad8e97ceb8517565f74285a Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 4 Jun 2012 23:24:52 +0000 Subject: Added code to handle joystick, and completed demo program. Ready to be used. --- WindowsPhone/JoystickTest/JoystickTest/Game1.cs | 30 ++++++++++-- .../JoystickTestContent/Courier New.spritefont | 52 +++++++++++++++++++++ .../JoystickTestContent.contentproj | 7 +++ WindowsPhone/KeyboardTest.suo | Bin 51712 -> 51712 bytes 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 WindowsPhone/JoystickTest/JoystickTestContent/Courier New.spritefont (limited to 'WindowsPhone') diff --git a/WindowsPhone/JoystickTest/JoystickTest/Game1.cs b/WindowsPhone/JoystickTest/JoystickTest/Game1.cs index 53560a7..09cbfd8 100644 --- a/WindowsPhone/JoystickTest/JoystickTest/Game1.cs +++ b/WindowsPhone/JoystickTest/JoystickTest/Game1.cs @@ -27,6 +27,10 @@ namespace JoystickTest Texture2D background; Texture2D button; Texture2D joystick; + SpriteFont font; + + string digitalState = "No event"; + string analogueState = "No event"; public Game1() { @@ -64,6 +68,7 @@ namespace JoystickTest { spriteBatch = new SpriteBatch(GraphicsDevice); + font = Content.Load("Courier New"); background = Content.Load("joystick_background"); joystick = Content.Load("joystick"); button = Content.Load("button"); @@ -72,11 +77,17 @@ namespace JoystickTest digital = new JoystickDriver(manager, GraphicsDevice, JoystickType.Digital, background, joystick, button, Vector2.Zero, new Vector2(100), new Vector2[2] {new Vector2(300, 50), new Vector2(300, 150)}, - 10, 100); + 25, 50); analogue = new JoystickDriver(manager, GraphicsDevice, JoystickType.Analogue, background, joystick, button, new Vector2(0, 300), new Vector2(100), new Vector2[1] {new Vector2(300, 150)}, - 10, 100); + 5, 50); + + digital.LockType = JoystickLock.EightWay; + analogue.LockType = JoystickLock.EightWay; + + digital.DigitalEvent += DigitalHandler; + analogue.AnalogueEvent += AnalogueHandler; } /// @@ -105,16 +116,29 @@ namespace JoystickTest /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { - GraphicsDevice.Clear(Color.White); + GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); digital.Draw(spriteBatch); analogue.Draw(spriteBatch); + spriteBatch.DrawString(font, digitalState, new Vector2(0, 700), Color.Yellow, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 1f); + spriteBatch.DrawString(font, analogueState, new Vector2(0, 720), Color.Green, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 1f); + spriteBatch.End(); base.Draw(gameTime); } + + private void DigitalHandler(object sender, JoystickDriver.DigitalJoystickEventArgs e) + { + digitalState = String.Format("{0} {1} {2}", e.State, e.Buttons[0], e.Buttons[1]); + } + + private void AnalogueHandler(object sender, JoystickDriver.AnalogueJoystickEventArgs e) + { + analogueState = String.Format("{0} {1}", e.State, e.Buttons[0]); + } } } diff --git a/WindowsPhone/JoystickTest/JoystickTestContent/Courier New.spritefont b/WindowsPhone/JoystickTest/JoystickTestContent/Courier New.spritefont new file mode 100644 index 0000000..ebefa68 --- /dev/null +++ b/WindowsPhone/JoystickTest/JoystickTestContent/Courier New.spritefont @@ -0,0 +1,52 @@ + + + + + + + Courier New + + + 28 + + + 2 + + + + + + + + + ~ + + + + \ No newline at end of file diff --git a/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj b/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj index abe9430..ce74723 100644 --- a/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj +++ b/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj @@ -46,6 +46,13 @@ TextureProcessor + + + Courier New + FontDescriptionImporter + FontDescriptionProcessor + +