Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / GetRawTouchCurrentX() returns 0.0 when GetPointerstate() = 1 and finger is not at 0.0

Author
Message
Dale Schultz
3
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 25th Nov 2021 01:35 Edited at: 25th Nov 2021 03:07
I am trying to understand why this is happening. I have some code below that looks for a swipe left or right.

I only look at the touch position if GetPointerstate()

During the touch event GetRawTouchCurrentX() returns correct values. However, after the finger is lifted, it returns a zero even while GetPointerstate() is still true.
I expect GetRawTouchCurrentX() to return actual values until GetPointerstate() returns zero.

Here is the code the demonstrates the issue:



When running the code, swipe your finger left or right, it can be seen that the swipe value is correct DURING the touch event but as soon as the event ends, it is always negative, even if you moved from left to right.
This is because GetRawTouchCurrentX() returned a zero and the original start position is subtracted from zero.

If you then uncomment the if and endif that checks for GetRawTouchCurrentX() returning 0.0 the code works as one would expect.
Even if one inspects the return value of GetPointerstate() after GetRawTouchCurrentX() one sees it is still non-zero so it not that the finger is being lifted between the execution of the GetPointerstate() and GetRawTouchCurrentX() calls.

Note that when moving the finger from left to right, and the initial position (tx) is positive, at no time is the finger ever at x position zero. Yet GetRawTouchCurrentX() returns 0.0

Excluding iterations where GetRawTouchCurrentX() = 0.0 avoids the problem for most cases but of course would fail if GetRawTouchCurrentX() is supposed to be zero.

This happens to me on Android 12

Can others reproduce this?
Am I missing something ?

The problem may be that GetPointerstate() is returning true for too long.
Dale Schultz
3
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 25th Nov 2021 02:37
well,


works much better!
I guess GetRawTouchReleased( ) is more responsive.

It implies that GetRawTouchReleased( ) and GetPointerstate() can both be true at the same time, but I have not tested that.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Nov 2021 16:18
Bear in mind, Touch functions use dedicated touch libs, Pointer use wrapped generic OS libs ....

GetPointerState wrote: "This is an emulated input method that uses whatever device inputs are available to produce a screen pointer."


I would not expect GetPointerState to be compatible with Touch functions without producing some side effects, use all RawTouch



Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Nov 2021 21:37
Quote: "after the finger is lifted, it returns a zero"


This is when flags are important I believe.

So holding a value in a different flag might help.

if GetPointerstate()=1 then mypointflag=1

if mypointflag=1
do what ever
endif

Your saying

while GetPointerstate()=1

So for the state to be always active



Dale Schultz
3
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 26th Nov 2021 22:32 Edited at: 26th Nov 2021 22:36
Quote: "if GetPointerstate()=1 then mypointflag=1"


well keeping a copy of the fact that the pointer was down in a separate flag, that never gets updated, would mean the loop would repeat forever. The object of the while loop is to only loop while the pointer is pressed.

So your suggestion would be the same at



We don't want to only loop forever, only while the pointer is down. We need to loop until the pointer is released so that we can get the x coordinate.
The bugs is that after we are told the pointer is still down, after it has in fact been released, so we then we get an incorrect value of the pointer X coordinate.
We cant keep a copy of the last 'good' return value because we don't know when it is the last good call.
The workaround for the bug is to check if we get a zero and ignore that value. That workaround would, however, fail if the correct result happened to be a zero.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Nov 2021 00:00 Edited at: 27th Nov 2021 00:06
this might help with Swipes: https://forum.thegamecreators.com/thread/195049

i think it's part of the larger Useful Community Functions (UCF) project listed referenced HERE.

meanwhile THIS re: inertia scroll/swipes mentions an android "bug" that was "fixed".
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Nov 2021 02:07
Quote: "We don't want to only loop forever"


Yes and this is a good way to stop the loop

If pointerisrelesed=1 then mypointflag=0

I understand where your going but if I had to do this and I have lately this is what I did.

Dale Schultz
3
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 27th Nov 2021 02:54
Quote: "If pointerisrelesed=1 then mypointflag=0"


There is no pointer release function. As I mentioned above there is a GetRawTouchReleased() function which does not return a false result (but does not work with a mouse on Windows)

All your code is doing is making a copy of the bad data. Using a copy of the bad data will not make a difference.
The workaround using the 'pointer' call is to check for a zero value and ignore it.

As as I said, I could also get it to work with GetRawTouchReleased() but because of the platform limitation of rawtouch calls, I have gone back to using 'pointer' and check for zero.

Part of the aim of this post is to check that I have not made a stupid coding error before writing up a bug report. It helps to have other eyes pick up something I have missed.

@VirtualNomad, thanks, I'll check out those links and bug to see if they are related before submitting a bug.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Nov 2021 03:00
GetRawMouseReleased() is what I use, it works the same way on all devises I've tested it on.

Mabey it will work, I don't know.

I find it funny how there is raw mouse and raw touch commands that do the same things.
Dale Schultz
3
Years of Service
User Offline
Joined: 1st Nov 2021
Location: Maine, USA
Posted: 27th Nov 2021 03:17 Edited at: 27th Nov 2021 03:18
Indeed, it looks like IronManhood ran into the same bug:

Quote: "Edit: Found a bug. Seems like on android it takes an extra frame to reset the pointer button commands."


This describes the same symptom.

I suspect that by
Quote: "Edit: Fixed."

he means he also worked around the problem, not that the bug got fixed.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Dec 2021 04:42
Quote: "I find it funny how there is raw mouse and raw touch commands that do the same things."


They do not do the same things, they may look similar but internally they use different messaging and callback systems, mouse: for example does not support multitouch, the latter is processed in a completely different way to mouse, if your game uses both (desktop and mobile0 you need to separate the logic.

Quote: "Edit: Found a bug.

......

mentions an android "bug" that was "fixed"."


Its not a bug, Android is waiting to process the input type, a long tap for example needs to process a few frames to register, so does a drag or swipe event, its the nature of multitouch and input gestures on capacitive input devices, this is why you MUST use only raw touch functions as a set because they work in conjunction with each other and are not compatible with raw mouse or pointer functions .....

a press and release on the droid needs at least 2 frames, if the press is still valid after frame 2 then it waits to process a long tap (about 3 seconds I think, depending on the device and your settings) if its still a press after that time its a touch, if on the second frame its not pressed it is a tap ..... if you think about it, it makes perfect sense.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Dec 2021 04:47 Edited at: 3rd Dec 2021 04:50
Here, this explains it better

GetRawTouchType wrote: "Returns the type of the given touch event. All you can be sure about with unknown events is that the finger is currently on screen and has been there less than 1 second. After 1 second it automatically becomes a hold event. If the user lifts their finger off the screen before this then it becomes a short event, and if they move their finger further than the distance specified by SetRawTouchMoveSensitivity then it becomes a drag event. If the current event is not known then it returns 0. Events may change from being hold events to being drag events, but short and drag events do not change type. Unknown events are guaranteed to change type once more information is available. Possible return values are 0 to indicate unknown, 1 for a short touch, 2 for a hold and 3 for dragging."
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Login to post a reply

Server time is: 2024-11-23 08:21:05
Your offset time is: 2024-11-23 08:21:05