XNAでZuneを動かす(その2)
■とりあえず、以前XNAで作ったスプライトを出すサンプルを動作させて見ます。
■ソース
namespace ZuneGame1 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; private SpriteBatch sprite; private 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(graphics.GraphicsDevice); texture = Content.Load<Texture2D>("mimi"); } 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) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); sprite.Begin(); Vector2 pos = new Vector2(0, 0); sprite.Draw(texture, pos, Color.White); sprite.End(); base.Draw(gameTime); } } }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); }
初期化のときにZuneでは「TargetElapsedTime」を指定してあげてください
デフォルトでは30フレになっていると思います。
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); base.Update(gameTime); }
ここでちゃんとExit処理を書いておかないと、Zuneで起動したあと、再起動しないと戻れなくなります。