summaryrefslogtreecommitdiff
path: root/WindowsPhone/JoystickTest/JoystickTest/Game1.cs
diff options
context:
space:
mode:
Diffstat (limited to 'WindowsPhone/JoystickTest/JoystickTest/Game1.cs')
-rw-r--r--WindowsPhone/JoystickTest/JoystickTest/Game1.cs30
1 files changed, 27 insertions, 3 deletions
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<SpriteFont>("Courier New");
background = Content.Load<Texture2D>("joystick_background");
joystick = Content.Load<Texture2D>("joystick");
button = Content.Load<Texture2D>("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;
}
/// <summary>
@@ -105,16 +116,29 @@ namespace JoystickTest
/// <param name="gameTime">Provides a snapshot of timing values.</param>
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]);
+ }
}
}