01 December 2009

Putting the code into XNA


I started by getting XNA to display the board, this is easy
as it is just a static background so I used the spriteBatch.
Vector2 tempVector = new Vector2(0, 0);
spriteBatch.Draw(background, tempVector, Color.White);

I also needed to resize the window in the Initialize() method...
this.graphics.PreferredBackBufferWidth = 224;
this.graphics.PreferredBackBufferHeight = 471;
this.graphics.ApplyChanges();

Then display the pieces on the board in their starting positions and finally the dice. It is only a 2d game but this seems really easy.
I needed to get mouse input. I used Mouse.GetState().
If the game was ever going to run on the XBox then this wouldn't be enough. Apparently they forgot to add a mouse when they designed the XBox. What were they thinking? I'd need to add support for a GamePad. I don't own an XBox so I am not too bothered about this.

KeyboardState keyboard = Keyboard.GetState();
MouseState mouse = Mouse.GetState();

Now, I can use mouse.X, mouse.Y and compare mouse.LeftButton with ButtonState.Pressed.

No comments: