This project has moved and is read-only. For the latest updates, please go here.

Maintain a previous state of a wiimote and get the current...

Apr 21, 2010 at 10:26 AM

Good morning.


My name is Luismi, and I'm programming a videogame for XNA using the WiimoteLib library. I'm trying to maintain the previous state of the wiimote, and then get the current state. Here is where i have the problem. When i try to get it, there is memory shared between attributes, so if i assign the current state to the previous state and then i modify the current state, the previous state is modified as well...

If i were programming with C++ i would know how to solve it, but with this managed memory i have trouble to work with pointers and references.... Any suggestion would be perfect.



Dec 13, 2010 at 2:56 PM

XNA uses structs to maintain the GamePadState, so when you call the prevState = currState, you are copying the values inside the struct.

WiimoteState is a class. To maintain a proper prevState, you must copy each of the variables themselves:
prevState.ButtonState.A = currState.ButtonState.A;
...And so on for each button.

Realistically, you should create a method to copy the values over.