Game Development Reference
In-Depth Information
auto& textureView = *m_core->GetWhiteTexture()->GetView();
m_spriteBatch->Draw(textureView, m_rectangle, nullptr, m_backgroundColor);
float y = m_rectangle.Top();
for (size_t i = 0; i < m_items.size(); ++i )
auto& item = m_items[i];
auto control = item->Control();
control->SetPosition(vector2(m_rectangle.Left(), y) );
if ( i == m_currentItemIndex )
y += control->Rectangle().Height();
white, the selected option will be drawn in red. During the iteration we also need to set the
position of each item by offsetting it vertically by the height of the control.
This type of menu has the advantage of using events to notify users of changes in menu
selection, in this way there is no requirement to derive from the menu class to implement
new menus. However, in some cases deriving provides us with a more specialized menu,
to support this it would be worth adding virtual functions that allow derived classes to im-
plement them.
virtual void OnAccept(control& ctrl) {}
virtual void OnCancel(control& ctrl) {}
virtual void OnSelection(control& ctrl) {}
We can add then the call to these functions at their respective place alongside their event.
if ( keyboard->KeyPressed(DIK_RETURN) || keyboard->KeyPressed(DIK_NUMPADENTER) ){
auto selectedControl = m_items[m_currentItemIndex]->Control();
m_onAccept.Invoke(this, *selectedControl);
return true;
use of a variety of controls to change game specific parameters such as sound and music
volumes, gamma correction, brightness controls, character customization options, etc.
Search WWH ::

Custom Search