Game Development Reference
In-Depth Information
Player input is detected by a class called Menu ; it informs the buttons if they
are selected or pressed. The Menu class contains a list of buttons, and only one
button may have focus at any one time. The user can navigate the menu with
the control pad or keyboard. The OnGainFocus and OnLoseFocus will
change the button label text; this will let us know which button currently has the
focus.
The color will be red when focused; otherwise, it will be black. Alternatively, the
text could be enlarged, a background image could change, or some other values
could be tweened in or out, but not now as this is the very first pass.
The menu will list the buttons vertically in a column, so a good name might be
VerticalMenu . VerticalMenu is another reusable class so it can be added
to the Engine project. The menu will need methods for adding buttons and a
Render method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Input; // Input needs to be added for gamepad input.
using System.Windows.Forms; // Used for keyboard input
namespace Engine
{
public class VerticalMenu
{
Vector _position ¼ new Vector();
Input.Input _input;
List < Button > _buttons ¼ new List < Button > ();
public double Spacing { get; set; }
public VerticalMenu(double x, double y, Input.Input input)
{
_input ¼ input;
_position ¼ new Vector(x, y, 0);
Spacing ¼ 50;
}
public void AddButton(Button button)
 
Search WWH ::




Custom Search