Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
using Microsoft.Xna.Framework.Input;
2
3
4
class RowSelectGameObject : SpriteGameObject
{
5
protected int selectedRow;
6
7
8
public RowSelectGameObject( int layer = 0, string id = "")
: base ("spr_selector_frame", layer, id)
9
{
10
selectedRow = 0;
11
}
12
13
14
public override void HandleInput(InputHelper inputHelper)
{
15
JewelGrid grid = GameWorld.Find("grid") as JewelGrid;
16
17
18
if (inputHelper.KeyPressed(Keys.Up))
−− ;
selectedRow
19
else if (inputHelper.KeyPressed(Keys.Down))
20
selectedRow++;
21
1);
selectedRow = ( int )MathHelper.Clamp(selectedRow, 0, grid.Rows
22
10, grid.CellHeight selectedRow 10);
this .position = new Vector2(
23
24
25
if (inputHelper.KeyPressed(Keys.Left))
grid.ShiftRowLeft(selectedRow);
26
else if (inputHelper.KeyPressed(Keys.Right))
27
grid.ShiftRowRight(selectedRow);
28
}
29
}
30
Listing 16.1 A new version of the row selection game object that uses the identifier system to find
game objects in the game world
be written and the font that is used. Finally, we also want to be able to change the
color of the text that is displayed. Therefore, the TextGameObject class has at least
the following member variables:
protected SpriteFont spriteFont;
protected Color color;
protected string text;
We can then override the Draw method to write text on the screen, which is done by
calling the DrawString method from the SpriteBatch class:
Search WWH ::




Custom Search