Game Development Reference
In-Depth Information
_label ¼ label;
_label.SetColor(new Color(0, 0, 0, 1));
UpdatePosition();
}
public void UpdatePosition()
{
// Center label text on position.
_label.SetPosition(_position.X - (_label.Width / 2),
_position.Y þ (_label.Height / 2));
}
public void OnGainFocus()
{
_label.SetColor(new Color(1, 0, 0, 1));
}
public void OnLoseFocus()
{
_label.SetColor(new Color(0, 0, 0, 1));
}
public void OnPress()
{
_onPressEvent(this, EventArgs.Empty);
}
public void Render(Renderer renderer)
{
renderer.DrawText(_label);
}
}
The button class doesn't directly handle the user input; instead, it relies on
whichever piece of code uses it to pass on relevant input events. The OnGain-
Focus and OnLoseFocus methods will be used to change the appearance of
the button depending on the focus. This will let the user know which button he
currently has selected. When the button position is changed, the label text posi-
tion is also updated and centered. EventHandler is used to hold the function
that will be called when the button is pressed. EventHandler describes a
delegate that takes an object and event argument's enum.
 
Search WWH ::




Custom Search