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:
iTouch as integer
msg as String
tx as float // initial touch position
swipe as float // distance swiped, negative to left, positive to right
bIncludeUnknown as integer = 1 // all touch events
do
if GetPointerstate() = 1 // pointer is down
iTouch = GetRawFirstTouchEvent(bIncludeUnknown )
tx = GetRawTouchStartX(iTouch) // this is where the touch event started
while GetPointerstate()=1 // finger is still in touch
//if GetRawTouchCurrentx(iTouch) > 0.0 // How can this be zero if finger never touches the left edge?
swipe = GetRawTouchCurrentx(iTouch) - tx // distance has the finger moved
//endif
print(swipe) // show that DURING the touch event we get correct values
msg = "last swipe start:" + str(tx) + " swipe:" + str(swipe) // keep the values to show after the event
sync() // update screen during the finger movement
endwhile // finger on screen
endif // pointer down
print(msg) // show the result obtained in the last pass through the while loop
sync()
loop
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.