07 December 2009

Highlighting moves

I added highlighting to show the square you are hovering over and the square the piece would move to with the current dice. To do this I am using PNG files with transparent backgrounds as follows

Background



Piece



Highlight



Put it all together



and for the destination cell

Background + Highlight


These only show up if there is a legal move for the piece hovered over using the current dice.

To display them I am adding them to a spriteBatch:

// start collecting sprites
spriteBatch.Begin();
...// where to display the sprite
Vector2 tempVector = new Vector2(x, y);
// display piece (a Texture2D)
spriteBatch.Draw(piece, tempVector, Color.White);
...
// finished collecting sprites
spriteBatch.End();

That's all it takes to display a 2D board game, lots of sprites displayed in the right place. Not too difficult.

No comments: