From 643c13f3ebd3240aa58f83a35a66909fdd9545d9 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 28 May 2012 22:46:59 +0000 Subject: Added test code to handle buttons to make sure drawing is OK. --- WindowsPhone/JoystickTest/JoystickTest/Game1.cs | 41 +++- .../JoystickTestContent.contentproj | 17 ++ .../JoystickTest/JoystickTestContent/button.png | Bin 0 -> 6594 bytes .../JoystickTest/JoystickTestContent/joystick.png | Bin 0 -> 16006 bytes .../JoystickTestContent/joystick_background.png | Bin 0 -> 109311 bytes .../Joystick/JoystickDriver.cs | 260 +++++++++++++-------- .../Joystick/JoystickState.cs | 37 ++- 7 files changed, 241 insertions(+), 114 deletions(-) create mode 100644 WindowsPhone/JoystickTest/JoystickTestContent/button.png create mode 100644 WindowsPhone/JoystickTest/JoystickTestContent/joystick.png create mode 100644 WindowsPhone/JoystickTest/JoystickTestContent/joystick_background.png diff --git a/WindowsPhone/JoystickTest/JoystickTest/Game1.cs b/WindowsPhone/JoystickTest/JoystickTest/Game1.cs index a5f8be3..53560a7 100644 --- a/WindowsPhone/JoystickTest/JoystickTest/Game1.cs +++ b/WindowsPhone/JoystickTest/JoystickTest/Game1.cs @@ -9,6 +9,8 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Media; +using Noddybox.Emulation.Xna.Input; +using Noddybox.Emulation.Xna.Input.Joystick; namespace JoystickTest { @@ -19,6 +21,12 @@ namespace JoystickTest { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; + InputManager manager; + JoystickDriver digital; + JoystickDriver analogue; + Texture2D background; + Texture2D button; + Texture2D joystick; public Game1() { @@ -45,8 +53,6 @@ namespace JoystickTest /// protected override void Initialize() { - // TODO: Add your initialization logic here - base.Initialize(); } @@ -56,10 +62,21 @@ namespace JoystickTest /// protected override void LoadContent() { - // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); - // TODO: use this.Content to load your game content here + background = Content.Load("joystick_background"); + joystick = Content.Load("joystick"); + button = Content.Load("button"); + + manager = new InputManager(); + + 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); + + 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); } /// @@ -78,12 +95,7 @@ namespace JoystickTest /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { - // Allows the game to exit - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) - this.Exit(); - - // TODO: Add your update logic here - + manager.Update(); base.Update(gameTime); } @@ -93,9 +105,14 @@ namespace JoystickTest /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { - GraphicsDevice.Clear(Color.CornflowerBlue); + GraphicsDevice.Clear(Color.White); + + spriteBatch.Begin(); + + digital.Draw(spriteBatch); + analogue.Draw(spriteBatch); - // TODO: Add your drawing code here + spriteBatch.End(); base.Draw(gameTime); } diff --git a/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj b/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj index 4ae643c..abe9430 100644 --- a/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj +++ b/WindowsPhone/JoystickTest/JoystickTestContent/JoystickTestContent.contentproj @@ -29,6 +29,23 @@ + + + button + TextureImporter + TextureProcessor + + + joystick + TextureImporter + TextureProcessor + + + joystick_background + TextureImporter + TextureProcessor + +