Game Development Reference
In-Depth Information
_currentFocus-;
if (_currentFocus == -1)
{
_currentFocus ΒΌ (_buttons.Count - 1);
}
ChangeFocus(oldFocus, _currentFocus);
}
private void ChangeFocus(int from, int to)
{
if (from != to)
{
_buttons[from].OnLoseFocus();
_buttons[to].OnGainFocus();
}
}
By pressing up or down on the keyboard, the focus is moved up and down the
buttons on the vertical menu. The focus also wraps around. If you are at the top
of the menu and press up, then the focus will wrap around and go to the bottom
of the menu. The ChangeFocus method reduces repeated code; it tells one
button it's lost focus and another button that it's gained focus.
Buttons can now be selected, but there is no code to handle buttons being
pressed. The VerticalMenu class needs to be modified to detect when the A
button on the gamepad or the Enter key on the keyboard is pressed. Once this is
detected, the currently selected button delegate is called.
// Inside the HandleInput function
else if(_input.Keyboard.IsKeyPressed(Keys.Up)
|| controlPadUp)
{
OnUp();
}
else if (_input.Keyboard.IsKeyPressed(Keys.Enter)
|| _input.Controller.ButtonA.Pressed)
{
OnButtonPress();
}
}
 
Search WWH ::




Custom Search