ZuneHD 傾きサンプル
Game1.cs
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; namespace ZuneGame2 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch sprite; Texture2D texture; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { sprite = new SpriteBatch(GraphicsDevice); texture = Content.Load<Texture2D>("ball"); } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { AccelerometerState aState = Accelerometer.GetState(); GraphicsDevice.Clear(Color.CornflowerBlue); sprite.Begin(SpriteBlendMode.Additive); sprite.Draw(texture, new Vector2((272/2)+aState.Acceleration.X*200, (480/2)-aState.Acceleration.Y*400), Color.White); sprite.End(); base.Draw(gameTime); } } }
ここの部分で、スプライトが画面の低いほうに表示されます。
sprite.Draw(texture, new Vector2((272/2)+aState.Acceleration.X*200, (480/2)-aState.Acceleration.Y*400), Color.White);
ZuneHDの画面サイズは272X480なので、中心から計算して表示しています。
-1.0 < aState.Acceleration.X < 1.0
-1.0 < aState.Acceleration.Y < 1.0
-1.0 < aState.Acceleration.Z < 1.0
各軸に対して -1.0から1.0の間で変化します。