MonoGame.Extended
MonoGame.Extended copied to clipboard
[Gui] Touch screen for iOS and Android support
Hi,
I use your GUI Controls (MonoGame.Extended.Gui) for an iOS Game and have a problem with the GuiButton class.
My buttons are created like this:
btnHighscore = new GuiButton();
btnHighscore.Position = new Vector2(100, 270);
btnHighscore.Text = "Highscore";
btnHighscore.Font = bitmapFont;
btnHighscore.Color = Color.Red;
btnHighscore.Size = new Size2(200, 50);
btnHighscore.Origin = new Vector2(0, 0);
btnHighscore.Clicked += BtnHighscoreClicked;
When clicking the button for the first time, the BtnHighscoreClicked()
method is not called, but every following click works as expected. This means that when a button is clicked for the first time, the user must always click twice.
As a workaround I’ve changed the method OnPointerDown()
in GuiSystem.cs:
private void OnPointerDown(GuiPointerEventArgs args)
{
if (Screen == null || !Screen.IsVisible)
return;
_preFocusedControl = FindControlAtPoint(Screen.Controls, args.Position);
// _hoveredControl is usually set in OnPointerMoved(). If OnPointerMoved()
// was not called, _hoveredControl is still null and OnPointerDown() will
// not be called.
if (_hoveredControl == null)
{
_hoveredControl = _preFocusedControl;
}
_hoveredControl?.OnPointerDown(this, args);
}