vchelaru / FlatRedBall

Cross-platform 2D game engine focused on ultimate productivity built in .NET
http://flatredball.com
MIT License
411 stars 65 forks source link

Inability to read touchscreen gestures as well as Gui.Cursor.PrimaryPush not registering when using an Android emulator or a connected android device (via USB) #126

Closed mza299 closed 2 years ago

mza299 commented 3 years ago

The issue is concerning a synced (desktop/android) project.

I used the following snippets of code to register a touchscreen "tap" input. This code is written in the CustomActivity method of a Screen/Scene .cs file.

foreach (var gesture in InputManager.TouchScreen.LastFrameGestures)
                {
                    if (gesture.GestureType == GestureType.Tap)
                    {
                        CalculateInitialHopDistance(); // a method that does something
                    }

                }

and

if (GuiManager.Cursor.PrimaryPush)
            {
                CalculateInitialHopDistance();
            }

The latter worked for the desktop project as expected.

However for both the android emulator and a connected hardware android device, there was no gestures registered and GuiManager.Cursor.PrimaryPush did not register as a touchscreen tap as mentioned in the FRB API.

The emulator simulates a Google Pixel 2 Pie (API 28, Android 9 Pie) My connected android device (hardware) via USB enabled debugging is a Xiaomi Redmi 3 (API, Android 5.1 Lollipop)

mza299 commented 3 years ago

Using the underlying XNA framework works. As in it registers touch input using an android emulator via VS2019. I used the following code:

while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gesture = TouchPanel.ReadGesture();

                if (gesture.GestureType == GestureType.Tap)
                {
                    CalculateInitialHopDistance();
                }
            }

This is the same code mentioned in the FRB API documentation. However, accessing the gestures through FlatRedBall.Input still does not work.

vchelaru commented 2 years ago

I know this bug is old and I apologize for not getting to it yet, but it looked like there was a workaround. Anyway, I'll address the two points:

Regarding Cursor.PrimaryPush, this has been fixed on Android and it should work just fine on both Android and DesktopGL projects. I don't know which commit this was fixed in, as it was a while ago.

The fix to InputManager.TouchPanel.LastFrameGestures was also added at some point in the past and it works correctly. As a test, I wrote the following code (in CustomActivity):

void CustomActivity(bool firstTimeCalled)
{
    foreach (var gesture in InputManager.TouchScreen.LastFrameGestures)
    {
        if (gesture.GestureType == GestureType.Tap)
        {
            var position = GuiManager.Cursor.WorldPosition;

            var circle = new Circle();
            circle.Visible = true;
            circle.Radius = 16;
            circle.Position = position.ToVector3();
        }
    }
}

This produced the following behavior:

22_07 30 32