- まず座標管理用にVector2を定義(float2つでもいい)
+ Vector2 pos;
// TODO: Add your initialization logic here
+ pos = new Vector2(0, 0);
- Updateで動かす
- GamePadは使えない(Windowsのゲームパッドが認識するかは不明だが、Xbox 360 ControllerのSupported on WindowsはYesになっている。)ので、Keyboardクラスからデータを取得し、カーソルキーで操作してみる。
// TODO: Add your update logic here
+ if (Keyboard.GetState().IsKeyDown(Keys.Left))
+ {
+ pos.X -= 1;
+ }
+ else if (Keyboard.GetState().IsKeyDown(Keys.Right))
+ {
+ pos.X += 1;
+ }
+ if (Keyboard.GetState().IsKeyDown(Keys.Up))
+ {
+ pos.Y -= 1;
+ }
+ else if (Keyboard.GetState().IsKeyDown(Keys.Down))
+ {
+ pos.Y += 1;
+ }
spriteBatch.Draw(texture, pos, Color.White);