Game Development Reference
In-Depth Information
{
double _currentY ¼ _position.Y;
if (_buttons.Count != 0)
{
_currentY ¼ _buttons.Last().Position.Y;
_currentY -= Spacing;
}
else
{
// It's the first button added it should have
// focus
button.OnGainFocus();
}
button.Position ¼ new Vector(_position.X, _currentY, 0);
_buttons.Add(button);
}
public void Render(Renderer renderer)
{
_buttons.ForEach(x = > x.Render(renderer));
}
}
}
The position of the buttons is handled automatically. Each time a button is
added, it is put below the other buttons on the Y axis. The Spacing member
determines how far apart the buttons are spaced, and this defaults to 50 pixels.
The menu itself also has a position that allows the buttons to be moved around as
a group. The position is only set in the constructor. The VerticalMenu
doesn't allow its position to be changed after it is constructed because this would
require an extra method to rearrange all the buttons for the new position. This
would be nice functionality to have, but it's not necessary. The Render method
uses C#'s new lamba operator to render all the buttons.
The menu class doesn't handle user input yet, but before adding that, let's hook
the menu up to StartMenuState so we can see if everything is working. The
label on buttons will use a different font than the one used for the title. Find
general_font.fnt and general_font.tga on the CD and add them to the project.
Then this new font needs to be set up in the Form.cs file.
 
Search WWH ::




Custom Search