It would be nice if someone could test the Zune code, since I now only own a Zune HD, and haven't been able to properly test it. I should also point out that the Zune and Zune HD code still need some work done to them, and I'll need to upgrade it soon to match SixOfEleven's code more closely, so users will be able to switch between Windows, Xbox and Zune a little easier.
Xin - XNA Input ManagerXNA Input Handler
27 Replies - 11642 Views - Last Post: 24 September 2010 - 09:00 AM
#17
Re: Xin - XNA Input Manager
Posted 16 April 2010 - 12:08 PM
WOW great work AMAZING.
time that will be deducted from xin = unlimited hours.
Seriously it's pretty awesome.
Edit: FYI I seriously would implement xin every. single. time I use any hardware input for my software.
If possible could you implement an X Y grabber for analog sticks? (I use ps3 controller)
Also if possible, try to make a way for people to send feedback(vibration) to a gamepad or controller.Never mind I just read it.
time that will be deducted from xin = unlimited hours.
Seriously it's pretty awesome.
Edit: FYI I seriously would implement xin every. single. time I use any hardware input for my software.
If possible could you implement an X Y grabber for analog sticks? (I use ps3 controller)
This post has been edited by FreezingHazard: 16 April 2010 - 12:15 PM
#18
Re: Xin - XNA Input Manager
Posted 16 April 2010 - 02:34 PM
Will send you the updated code lesPaul456. Almost have everything ready to go for others to test. Just want to set up the web page for downloads and finish up the documentation. Added in a few extra methods and such. Would be helpful if anybody with a Zune would like to test the Zune version. Hope to have this up tonight.
#19
Re: Xin - XNA Input Manager
Posted 17 April 2010 - 10:30 AM
Xin for Windows and the Xbox 360 is now available, for both XNA 3.0 and XNA 3.1! You can find the links to the Xin game libraries on my new web site http://www.xnagpa.net/xin.html To use Xin, you follow these steps:
All of the public methods and properties of Xin are static so you reference them using the class name, Xin. When working with the methods for the game pad you pass in an enum for the PlayerIndex that you want to use. There are also overloads of those methods that don't take a PlayerIndex parameter that work with PlayerIndex.One.
Keyboard Methods
KeyboardState Xin.KeyboardState
Property that returns the current state of the keyboard.
KeyboardState Xin.LastKeyboardState
Property that returns the state of the keyboard in the last frame of the game.
bool Xin.CheckKeyPress(Keys key)
Method that checks for a single press of the key specified by checking key was down in the last frame and up in the current frame. Returns true if the key was pressed exactly once and false otherwise.
bool Xin.IsKeyDown(Keys key)
Method that checks if the key specified by key is currently down. Returns true if the key is down and false otherwise.
bool Xin.IsKeyUp(Keys key)
Method that checks if the key specified by key is currently up. Returns true if the key is up and false otherwise.
bool Xin.LastIsKeyDown(Keys key)
Method that checks if the key specified by key was down in the last frame of the game.. Returns true if the key was down and false otherwise.
bool Xin.LastIsKeyDown(Keys key)
Method that checks if the key specified by key was up in the last frame of the game.. Returns true if the key is down and false otherwise.
Keys[] Xin.GetPressedKeys()
Method that returns an array of Keys that are currently down.
Keys[] Xin.LastPressedKeys()
Method that returns an array of Keys that were down in the last frame of the game.
Mouse Methods
MouseState Xin.MouseState
Property that returns the current state of the mouse.
MouseState Xin.LastMouseState
Property the returns the state of the mouse in the last frame of the game.
Point Xin.MouseAsPoint
Property that returns a Point that represents the location of the mouse relative to the upper left corner of the client area.
Vector2 Xin.MouseAsVector2
Property that returns a Vector2 that represents the location of the mouse relative to the upper left corner of the client area.
Point Xin.LastMouseAsPoint
Property that returns a Point that represents the location of the mouse relative to the upper left corner of the client area in the last frame of the game.
Vector2 Xin.LastMouseAsVector2
Property that returns a Vector2 that represents the location of the mouse relative to the upper left corner of the client area client are in the last frame of the game.
bool CheckMousePress(MouseButton button)
Method that checks to see if the button on the mouse specified by button was clicked exactly once by checking the button was down in the last frame of the game and up in the current frame of the game. This method calls private methods in Xin that detect clicks using the MouseState class. Returns true if the button was clicked once and false otherwise.
bool IsMouseDown(MouseButton button)
Method that checks to see if the mouse button specified by button is currently down. Returns true if the button is currently down and false otherwise.
bool IsMouseUp(MouseButton button)
Method that checks to see if the mouse button specified by button is current up. Returns true if the button is current up and false if it is no.
bool IsLastMouseDown(MouseButton button)
Method that checks to see if the mouse button specified by button is currently down. Returns true if the button was down in the last frame of the game and false otherwise.
bool IsLastMouseUp(MouseButton button)
Method that checks to see if the mouse button specified by button was up in the last frame. Returns true if the button was up in the last from of the game and false otherwise.
Game Pad Mehtods
GamePadState GamePadState(PlayerIndex index)
Method that gets the current state of the game pad referenced by index.
GamePadState GamePadState()
Overload that returns the state of the game pad for PlayerIndex.One.
GamePadState LastGamePadState(PlayerIndex index)
Method that gets the state of the game pad referenced by index.
GamePadState LastGamePadState()
Overload that returns the state of the game pad for PlayerIndex.One.
bool IsConnected(PlayerIndex index)
Method that returns if the game pad referenced by index is currently connected. Returns true if the game pad is connected and false otherwise. Normally you should only us the method IsConnected(playerIndex) after a call to GamePad.GetState(playerIndex) but Xin takes care of this for you automatically because it is a game component that updates itself.
bool IsConnected()
Overload that returns if game pad PlayerIndex.One is connected.
GamePadButtons GamePadButtons(PlayerIndex index)
Method that gets the state of the buttons on the game pad referenced by index.
GamePadButtons GamePadButtons()
Overload that returns the state of the buttons on the game pad for PlayerIndex.One.
GamePadButtons LastGamePadButtons(PlayerIndex index)
Method that gets the state of the buttons on the game pad referenced by index in the last frame of the game.
GamePadButtons LastGamePadButtons()
Overload that returns the state of the buttons on the game pad for PlayerIndex.One in the last frame of the game.
void Vibrate(PlayerIndex index, float leftMotor, float rightMotor)
Method for setting the vibration speed of the motors in the game pad referenced by index. The leftMotor and rightMotor values are between 0.0f and 1.0f.
void Vibrate(float leftMotor, float rightMotor)
Overload of the method that vibrates the motors for PlayerIndex.One.
void StopVibration(PlayerIndex index)
Method that stops the motors in the game pad referenced by index.
void StopVibration()
Overload that stops the vibration of the motors in game pad PlayerIndex.One.
Vector2 LeftThumb(PlayerIndex index)
Method that returns the state of the left thumb stick of the game pad referenced by index as a Vector2.
Vector2 LeftThumb()
Overload that returns the state of the left thumb stick for PlayerIndex.One as a Vector2.
Vector2 RightThumb(PlayerIndex index)
Method that returns the state of the right thumb stick of the game pad referenced by index as a Vector2.
Vector2 RightThumb()
Overload that returns the state of the right thumb stick for PlayerIndex.One as a Vector2.
Vector2 LastLeftThumb(PlayerIndex index)
Method that returns the state of the left thumb stick of the game pad referenced by index as a Vector2 in the last frame of the game.
Vector2 LastLeftThumb()
Overload that returns the state of the left thumb stick for PlayerIndex.One as a Vector2 in the last frame of the game.
Vector2 LastRightThumb(PlayerIndex index)
Method that returns the state of the right thumb stick of the game pad referenced by index as a Vector2 in the last frame of the game.
Vector2 LastRightThumb()
Overload that returns the state of the right thumb stick for PlayerIndex.One as a Vector2 in the last frame of the game.
GamePadDPad DPad(PlayerIndex index)
Method that returns the state of the direction pad of the game pad referenced by index as GamePadDPad.
GamePadDPad DPad()
Overload that returns the state of the direction pad for the game pad referenced by PlayerIndex.One.
GamePadDPad LastDPad(PlayerIndex index)
Method that returns the state of the direction pad of the game pad referenced by index as GamePadDPad in the last frame of the game.
GamePadDPad LastDPad()
Overload that returns the state of the direction pad for the game pad referenced by PlayerIndex.One in the last frame of the game.
GamePadTriggers Triggers(PlayerIndex index)
Method that returns the state of the triggers of the game pad referenced by index as GamePadTriggers.
GamePadTriggers Triggers()
Overload of the method that returns the state of the triggers of the game pad referenced by PlayerIndex.One.
GamePadTriggers LastTriggers(PlayerIndex index)
Method that returns the state of the triggers of the game pad referenced by index as GamePadTriggers in the last frame of the game.
GamePadTriggers LastTriggers()
Overload of the method that returns the state of the triggers of the game pad referenced by PlayerIndex.One in the last frame of the game.
float LeftTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the current state of the left trigger of the game pad referenced by index.
float LeftTrigger()
Overload of the method that returns the state of the left trigger for the game pad referenced by PlayerIndex.One.
float LastLeftTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the state of the left trigger in the last frame of the game for the game pad referenced by index.
float LastLeftTrigger()
Overload of the method that returns the state of the left trigger for the game pad referenced by PlayerIndex.One in the last frame of the game.
float RightTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the current state of the right trigger of the game pad referenced by index.
float RightTrigger()
Overload of the method that returns the state of the right trigger for the game pad referenced by PlayerIndex.One.
float LastRightTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the state of the right trigger in the last frame of the game for the game pad referenced by index.
float LastRightTrigger()
Overload of the method that returns the state of the right trigger for the game pad referenced by PlayerIndex.One in the last frame of the game.
Here is sample code of implementing Xin in a new game.
Alternatively, in the constructor you can just do the following.
- Add the appropriate Xin game library to your solution, named XInputManager
- Add a reference to the library for any project in your solution that you want to use Xin in
- Create an instance of Xin and add it to the list of game components
- Add a using statement for the XInputManager namespace
- Use the class name to refernce the static properties and methods of Xin
All of the public methods and properties of Xin are static so you reference them using the class name, Xin. When working with the methods for the game pad you pass in an enum for the PlayerIndex that you want to use. There are also overloads of those methods that don't take a PlayerIndex parameter that work with PlayerIndex.One.
Keyboard Methods
KeyboardState Xin.KeyboardState
Property that returns the current state of the keyboard.
KeyboardState Xin.LastKeyboardState
Property that returns the state of the keyboard in the last frame of the game.
bool Xin.CheckKeyPress(Keys key)
Method that checks for a single press of the key specified by checking key was down in the last frame and up in the current frame. Returns true if the key was pressed exactly once and false otherwise.
bool Xin.IsKeyDown(Keys key)
Method that checks if the key specified by key is currently down. Returns true if the key is down and false otherwise.
bool Xin.IsKeyUp(Keys key)
Method that checks if the key specified by key is currently up. Returns true if the key is up and false otherwise.
bool Xin.LastIsKeyDown(Keys key)
Method that checks if the key specified by key was down in the last frame of the game.. Returns true if the key was down and false otherwise.
bool Xin.LastIsKeyDown(Keys key)
Method that checks if the key specified by key was up in the last frame of the game.. Returns true if the key is down and false otherwise.
Keys[] Xin.GetPressedKeys()
Method that returns an array of Keys that are currently down.
Keys[] Xin.LastPressedKeys()
Method that returns an array of Keys that were down in the last frame of the game.
Mouse Methods
MouseState Xin.MouseState
Property that returns the current state of the mouse.
MouseState Xin.LastMouseState
Property the returns the state of the mouse in the last frame of the game.
Point Xin.MouseAsPoint
Property that returns a Point that represents the location of the mouse relative to the upper left corner of the client area.
Vector2 Xin.MouseAsVector2
Property that returns a Vector2 that represents the location of the mouse relative to the upper left corner of the client area.
Point Xin.LastMouseAsPoint
Property that returns a Point that represents the location of the mouse relative to the upper left corner of the client area in the last frame of the game.
Vector2 Xin.LastMouseAsVector2
Property that returns a Vector2 that represents the location of the mouse relative to the upper left corner of the client area client are in the last frame of the game.
bool CheckMousePress(MouseButton button)
Method that checks to see if the button on the mouse specified by button was clicked exactly once by checking the button was down in the last frame of the game and up in the current frame of the game. This method calls private methods in Xin that detect clicks using the MouseState class. Returns true if the button was clicked once and false otherwise.
bool IsMouseDown(MouseButton button)
Method that checks to see if the mouse button specified by button is currently down. Returns true if the button is currently down and false otherwise.
bool IsMouseUp(MouseButton button)
Method that checks to see if the mouse button specified by button is current up. Returns true if the button is current up and false if it is no.
bool IsLastMouseDown(MouseButton button)
Method that checks to see if the mouse button specified by button is currently down. Returns true if the button was down in the last frame of the game and false otherwise.
bool IsLastMouseUp(MouseButton button)
Method that checks to see if the mouse button specified by button was up in the last frame. Returns true if the button was up in the last from of the game and false otherwise.
Game Pad Mehtods
GamePadState GamePadState(PlayerIndex index)
Method that gets the current state of the game pad referenced by index.
GamePadState GamePadState()
Overload that returns the state of the game pad for PlayerIndex.One.
GamePadState LastGamePadState(PlayerIndex index)
Method that gets the state of the game pad referenced by index.
GamePadState LastGamePadState()
Overload that returns the state of the game pad for PlayerIndex.One.
bool IsConnected(PlayerIndex index)
Method that returns if the game pad referenced by index is currently connected. Returns true if the game pad is connected and false otherwise. Normally you should only us the method IsConnected(playerIndex) after a call to GamePad.GetState(playerIndex) but Xin takes care of this for you automatically because it is a game component that updates itself.
bool IsConnected()
Overload that returns if game pad PlayerIndex.One is connected.
GamePadButtons GamePadButtons(PlayerIndex index)
Method that gets the state of the buttons on the game pad referenced by index.
GamePadButtons GamePadButtons()
Overload that returns the state of the buttons on the game pad for PlayerIndex.One.
GamePadButtons LastGamePadButtons(PlayerIndex index)
Method that gets the state of the buttons on the game pad referenced by index in the last frame of the game.
GamePadButtons LastGamePadButtons()
Overload that returns the state of the buttons on the game pad for PlayerIndex.One in the last frame of the game.
void Vibrate(PlayerIndex index, float leftMotor, float rightMotor)
Method for setting the vibration speed of the motors in the game pad referenced by index. The leftMotor and rightMotor values are between 0.0f and 1.0f.
void Vibrate(float leftMotor, float rightMotor)
Overload of the method that vibrates the motors for PlayerIndex.One.
void StopVibration(PlayerIndex index)
Method that stops the motors in the game pad referenced by index.
void StopVibration()
Overload that stops the vibration of the motors in game pad PlayerIndex.One.
Vector2 LeftThumb(PlayerIndex index)
Method that returns the state of the left thumb stick of the game pad referenced by index as a Vector2.
Vector2 LeftThumb()
Overload that returns the state of the left thumb stick for PlayerIndex.One as a Vector2.
Vector2 RightThumb(PlayerIndex index)
Method that returns the state of the right thumb stick of the game pad referenced by index as a Vector2.
Vector2 RightThumb()
Overload that returns the state of the right thumb stick for PlayerIndex.One as a Vector2.
Vector2 LastLeftThumb(PlayerIndex index)
Method that returns the state of the left thumb stick of the game pad referenced by index as a Vector2 in the last frame of the game.
Vector2 LastLeftThumb()
Overload that returns the state of the left thumb stick for PlayerIndex.One as a Vector2 in the last frame of the game.
Vector2 LastRightThumb(PlayerIndex index)
Method that returns the state of the right thumb stick of the game pad referenced by index as a Vector2 in the last frame of the game.
Vector2 LastRightThumb()
Overload that returns the state of the right thumb stick for PlayerIndex.One as a Vector2 in the last frame of the game.
GamePadDPad DPad(PlayerIndex index)
Method that returns the state of the direction pad of the game pad referenced by index as GamePadDPad.
GamePadDPad DPad()
Overload that returns the state of the direction pad for the game pad referenced by PlayerIndex.One.
GamePadDPad LastDPad(PlayerIndex index)
Method that returns the state of the direction pad of the game pad referenced by index as GamePadDPad in the last frame of the game.
GamePadDPad LastDPad()
Overload that returns the state of the direction pad for the game pad referenced by PlayerIndex.One in the last frame of the game.
GamePadTriggers Triggers(PlayerIndex index)
Method that returns the state of the triggers of the game pad referenced by index as GamePadTriggers.
GamePadTriggers Triggers()
Overload of the method that returns the state of the triggers of the game pad referenced by PlayerIndex.One.
GamePadTriggers LastTriggers(PlayerIndex index)
Method that returns the state of the triggers of the game pad referenced by index as GamePadTriggers in the last frame of the game.
GamePadTriggers LastTriggers()
Overload of the method that returns the state of the triggers of the game pad referenced by PlayerIndex.One in the last frame of the game.
float LeftTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the current state of the left trigger of the game pad referenced by index.
float LeftTrigger()
Overload of the method that returns the state of the left trigger for the game pad referenced by PlayerIndex.One.
float LastLeftTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the state of the left trigger in the last frame of the game for the game pad referenced by index.
float LastLeftTrigger()
Overload of the method that returns the state of the left trigger for the game pad referenced by PlayerIndex.One in the last frame of the game.
float RightTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the current state of the right trigger of the game pad referenced by index.
float RightTrigger()
Overload of the method that returns the state of the right trigger for the game pad referenced by PlayerIndex.One.
float LastRightTrigger(PlayerIndex index)
Method that returns a value between 0.0f and 1.0f for the state of the right trigger in the last frame of the game for the game pad referenced by index.
float LastRightTrigger()
Overload of the method that returns the state of the right trigger for the game pad referenced by PlayerIndex.One in the last frame of the game.
Here is sample code of implementing Xin in a new game.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
// using statement for the XInputManager namespace
using XInputManager;
namespace XinTestGame
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
// Field used for the Xin Game Component
Xin xinComponent;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Create an instance of the Xin Game Component and add
// it to the list of game components.
xinComponent = new Xin(this);
Components.Add(xinComponent);
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit if the back button on game pad one is down
if (Xin.IsButtonDown(Buttons.Back))
this.Exit();
// Allows the game to exit by checking if the escape key was pressed once
if (Xin.CheckKeyPress(Keys.Escape))
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
Alternatively, in the constructor you can just do the following.
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Create an instance of the Xin Game Component and add
// it to the list of game components.
Components.Add(new Xin(this));
}
#20
Re: Xin - XNA Input Manager
Posted 17 April 2010 - 10:39 AM
So maybe I'm blind but where can this be downloaded?
#21
Re: Xin - XNA Input Manager
Posted 17 April 2010 - 10:56 AM
Right at the top of my post, there is a link to my site where it can be downloaded. It was broken, but I just fixed it.
These are the direct links to the projects.
Xin Windows, XNA 3.0
Xin Windows, XNA 3.1
Xin Xbox 360, XNA 3.0
Xin Xbox 360, XNA 3.1
These are the direct links to the projects.
Xin Windows, XNA 3.0
Xin Windows, XNA 3.1
Xin Xbox 360, XNA 3.0
Xin Xbox 360, XNA 3.1
#22
Re: Xin - XNA Input Manager
Posted 30 April 2010 - 02:21 PM
I have an idea for a few more additions to Xin. One is getting an array of key presses returned. If a key was down last frame and currently up, it will be returned in an array of Keys. Adding in some similar mouse and game pad methods as well.
I'm also looking at adding in events that can be subscribed to. Like, KeyDown, MouseDown, MouseMove, and more. Also have an idea for having a virtual mouse with the Xbox 360 game pad.
I'm also looking at adding in events that can be subscribed to. Like, KeyDown, MouseDown, MouseMove, and more. Also have an idea for having a virtual mouse with the Xbox 360 game pad.
#23
Re: Xin - XNA Input Manager
Posted 03 May 2010 - 06:32 AM
Got started working with events with Xin yesterday. I do have to say, they are pretty cool.
In the spirit of Xin, I made the event I tested static so you don't need to have a reference to Xin in every class that you are working on. Found that it made life 100% easier doing it that way. The event that I started with is called KeyPressed. You can subscribe to the event, catch the event, and process the event. Event driven programming isn't exactly how XNA was supposed to work but you can fit it in rather nicely.
So, how does this work? The first thing you do is in the constructor of the class is wire the event. I will demonstate wiring an event that will exit the game if the player presses the Escape key, not just holds it down but presses it exactly once.
Then in the handler you can process the event. For KeyPressed I have a List<Keys> of all the keys that were pressed and released. You can use the Contains method of the List<T> class to see if the key you are interested in is in the list.
This is a rather trivial example and you could easily achieve the same effect in the Update method checking if the Escape key has been pressed. The potential however is there for much more.
So, how does this work? The first thing you do is in the constructor of the class is wire the event. I will demonstate wiring an event that will exit the game if the player presses the Escape key, not just holds it down but presses it exactly once.
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Components.Add(new Xin(this));
Xin.KeyPressed += new Xin.KeyPressedEventHandler(Xin_KeyPressed);
}
Then in the handler you can process the event. For KeyPressed I have a List<Keys> of all the keys that were pressed and released. You can use the Contains method of the List<T> class to see if the key you are interested in is in the list.
void Xin_KeyPressed(object sender, KeypressEventArgs e)
{
if (e.KeysPressed.Contains(Keys.Escape))
this.Exit();
}
This is a rather trivial example and you could easily achieve the same effect in the Update method checking if the Escape key has been pressed. The potential however is there for much more.
#24
Re: Xin - XNA Input Manager
Posted 06 May 2010 - 04:29 PM
I created more events and modified the one I had made. I also added in a new property, WasKeyPressed. WasKeyPressed is true if there has been a single key press and false otherwise. The event code has changed so that instead of returning a List<Keys> as the event arg it returns a single Keys variable. The method can be triggered multiple times though so all key presses are still captured. I have KeyDown and KeyUp events as well. I'm not sure I will keep the KeyUp though. I have events for the mouse as well: MouseDown, MouseUp, MousePressed, and MouseMove. I haven't started with the game pad yet but I don't see it being more difficult other than the fact that there can be four game pads connected at a time.
#25
Re: Xin - XNA Input Manager
Posted 24 May 2010 - 02:49 PM
I did add a new method to Xin called Flush. I found it useful when working with events. Basically it resets the input so that there are no single presses in the events. I have been working with events and they are truly very, very helpful when working with XNA games.
#26
Re: Xin - XNA Input Manager
Posted 22 July 2010 - 09:04 AM
I have been, when time permits, adding in events to Xin. I have the keyboard events all coded. The first one is KeyPressed. This event will be fired when a key that was down in the last frame is up in the current frame. There is also a KeyReleased event that works in the opposite way. It is fired when a key that was down in the last frame is fired in the current frame. The last keyboard event is KeyDown. This is fired every frame for any key that is currently down.
I plan on working with the mouse in the near future but since I'm going to be developing on my Xbox I will be focusing on the game pad first.
I plan on working with the mouse in the near future but since I'm going to be developing on my Xbox I will be focusing on the game pad first.
#27
Re: Xin - XNA Input Manager
Posted 17 September 2010 - 01:50 PM
I started using the Xin system.. but either I am not using it full potential or I need to set up extra checks or something, it will still cascade through the menus
so in this senario.. if I select menuA item 1, it will fly all the way to menuC item 1
the only way to stop this is if I decided to create new screen and do a screen change
the doOnce bool sort of worked for menuA and menuB, but one I add menuC it fails, I've tried a integer set up - but I still haven't got the logic right to make the button confirmation to pause
I may have to figure out a way - of timing the keystroke/button then comparing it somehow...
menuA
menuA item 1 : button A confirm
menuB
menuB item 1 : button A confirm
menuC
menuC item 1 : button A confirm
menuC item 2 : button A confirm
menuB item 2 : button A confirm
menuB item 3 : button A confirm
menuB item 4 : button A confirm
menuA item 2 : button A confirm
menuA item 3 : button A confirm
menuA item 4 : button A confirm
so in this senario.. if I select menuA item 1, it will fly all the way to menuC item 1
the only way to stop this is if I decided to create new screen and do a screen change
the doOnce bool sort of worked for menuA and menuB, but one I add menuC it fails, I've tried a integer set up - but I still haven't got the logic right to make the button confirmation to pause
I may have to figure out a way - of timing the keystroke/button then comparing it somehow...
#28
Re: Xin - XNA Input Manager
Posted 24 September 2010 - 09:00 AM
I discovered that problem Bixel and the solution to it. I just haven't updated Xin yet to fix it. What I did was create a method in Xin to clear the input buffer to prevent the cascading. When you are afraid that input is going to carry over you just call the method to reset the input. This is the code for that method.
Calling this method before switching states makes the condition that evaluated to true evaluate to false instead. Hope this is helpful.
public static void FlushInput()
{
lastKeyboardState = keyboardState;
#if !XBOX360
lastMouseState = mouseState;
#endif
for (int i = 0; i < gamePadState.Length; i++)
lastGamePadState[i] = gamePadState[i];
}
Calling this method before switching states makes the condition that evaluated to true evaluate to false instead. Hope this is helpful.

New Topic/Question
Reply



MultiQuote



|