Codes are from
https://forum.thegamecreators.com/thread/195049
decent accuracy, but when you swipe longer or if your swipe is not straight it will not display the right gestures
so how to improve this codes accuracy in gesture?
Gesture v1
Global _UCFSwipeRightTime as Float
Global _UCFSwipeRightX as Integer
Global _UCFSwipeLeftTime as Float
Global _UCFSwipeLeftX as Integer
Global _UCFSwipeDownTime as Float
Global _UCFSwipeDownY as Integer
Global _UCFSwipeUpTime as Float
Global _UCFSwipeUpY as Integer
SetVirtualResolution( 600, 1024 )
SetDisplayAspect( 600 / 1024 )
do
If GetSwipeRight( 0.1, 30 ) = 1 then Flag$ = "You Swiped Right"
If GetSwipeLeft( 0.1, 30 ) = 1 then Flag$ = "You Swiped Left"
If GetSwipeDown( 0.1, 30 ) = 1 then Flag$ = "You Swiped Down"
If GetSwipeUp( 0.1, 30 ) = 1 then Flag$ = "You Swiped Up"
If GetRawKeyPressed( 27 ) = 1 then END
Print(Flag$)
Sync()
loop
Function GetSwipeRight( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeRightTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeRightX = GetPointerX() + s
If GetPointerState() = 1 and _UCFSwipeRightTime < Timer()
If _UCFSwipeRightX < GetPointerX()
_UCFSwipeRightTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeLeft( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeLeftTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeLeftX = GetPointerX() - s
If GetPointerState() = 1 and _UCFSwipeLeftTime < Timer()
If _UCFSwipeLeftX > GetPointerX()
_UCFSwipeLeftTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeDown( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeDownTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeDownY = GetPointerY() + s
If GetPointerState() = 1 and _UCFSwipeDownTime < Timer()
If _UCFSwipeDownY < GetPointerY()
_UCFSwipeDownTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeUp( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeUpTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeUpY = GetPointerY() - s
If GetPointerState() = 1 and _UCFSwipeUpTime < Timer()
If _UCFSwipeUpY > GetPointerY()
_UCFSwipeUpTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Inaccurate Gestures in v2, how to fix this? this is worst in touchscreen than mouse
Gestures version2
Global _UCFSwipeRightTime as Float
Global _UCFSwipeRightX as Integer
Global _UCFSwipeLeftTime as Float
Global _UCFSwipeLeftX as Integer
Global _UCFSwipeDownTime as Float
Global _UCFSwipeDownY as Integer
Global _UCFSwipeUpTime as Float
Global _UCFSwipeUpY as Integer
SetVirtualResolution( 1024, 600 )
SetDisplayAspect( 1024 / 600 )
do
If GetSwipeRight( 0.1, 30 ) = 1 then Flag$ = "You Swiped Right"
If GetSwipeLeft( 0.1, 30 ) = 1 then Flag$ = "You Swiped Left"
If GetSwipeDown( 0.1, 30 ) = 1 then Flag$ = "You Swiped Down"
If GetSwipeUp( 0.1, 30 ) = 1 then Flag$ = "You Swiped Up"
If GetRawKeyPressed( 27 ) = 1 then END
Print(Flag$)
Sync()
loop
Function GetSwipeRight( t#, d )
Output = 0
If GetPointerPressed() = 1
_UCFSwipeRightX = GetPointerX() + d
_UCFSwipeRightTime = Timer() + t#
EndIf
If GetPointerState() = 1 and _UCFSwipeRightTime < Timer() and _UCFSwipeRightX < GetPointerX()
_UCFSwipeRightTime = 0
Output = 1
EndIf
EndFunction Output
Function GetSwipeLeft( t#, d )
Output = 0
If GetPointerPressed() = 1
_UCFSwipeLeftX = GetPointerX() - d
_UCFSwipeLeftTime = Timer() + t#
EndIf
If GetPointerState() = 1 and _UCFSwipeLeftTime < Timer() and _UCFSwipeLeftX > GetPointerX()
_UCFSwipeLeftTime = 0
Output = 1
EndIf
EndFunction Output
Function GetSwipeDown( t#, d )
Output = 0
If GetPointerPressed() = 1
_UCFSwipeDownY = GetPointerY() + d
_UCFSwipeDownTime = Timer() + t#
EndIf
If GetPointerState() = 1 and _UCFSwipeDownTime < Timer() and _UCFSwipeDownY > GetPointerY()
_UCFSwipeDownTime = 0
Output = 1
EndIf
EndFunction Output
Function GetSwipeUp( t#, d )
Output = 0
If GetPointerPressed() = 1
_UCFSwipeUpY = GetPointerY() - d
_UCFSwipeUpTime = Timer() + t#
EndIf
If GetPointerState() = 1 and _UCFSwipeUpTime < Timer() and _UCFSwipeUpY > GetPointerY()
_UCFSwipeUpTime = 0
Output = 1
EndIf
EndFunction Output