I was just messing around with my Zune HD while taking a short break from my main project when I thought I could port my TinyEngine to it in no time.
…
Sure enough, it took about 12 seconds.
In my dummy project I have Mr Tiny just smiling away in the center of the screen.
I wanted to get him to move around by just using the accelerometer. This was really simple.
I just call Accelerometer.GetState(); which returns a AccelerometerState. The AccelerometerState contains a Acceleration of type Vector3 which contains the direction of the accelerometer. I then just pass the direction of tilt to my engines Sprite Move command, as a Vector2.
Something like this
Vector2 accel = new Vector2(state.Acceleration.X, -state.Acceleration.Y);
AccelerometerState state = Accelerometer.GetState();
Vector2 accel = new Vector2(state.Acceleration.X, -state.Acceleration.Y);
this.mrTiny.Move(accel * 100 * elapsed);
Clamp it to the screen
this.mrTiny.PositionX = MathHelper.Clamp(this.mrTiny.PositionX, this.ScreenBounds.Left, this.ScreenBounds.Right);
this.mrTiny.PositionY = MathHelper.Clamp(this.mrTiny.PositionY, this.ScreenBounds.Top, this.ScreenBounds.Bottom);
And there we have it, you can tilt your Zune HD to move around Mr Tiny.
Short but sweet uh?
The code is linked just below. I’ll be looking to do more Zune HD samples in the near future, as well as adding gesture support to TinyEngine.
Once I’m finished with my secret project.
Nice, I’m still waiting for zune hd on europe =(
Thank you! I’ve been trying to do just this to test out how the accelerometer, and I couldn’t for the life of me get it working.
All I was missing was “AccelerometerState state = Accelerometer.GetState();” every frame.