I am very proud to present you my own version of swipe control. It's super simple, very easy to read and reusable if you're ever going to need swiping control in your mobile game
To change the area that specific swipe is covering just play with angle numbers and be careful to not overlap. ( To understand better how angles are working in AppGameKit just enable line Print(swipe) )
Special thanks to user Bengismo who showed me existence of Atan2 function.
// Project: swipe control
// Created: 2018-07-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "swipe control" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
swipe as string
do
touch = GetRawFirstTouchEvent(1)
angle = ATan2(GetRawTouchCurrentY(1)-GetRawTouchStartY(1), GetRawTouchCurrentX(1)-GetRawTouchStartX(1))
//swipe LEFT
if touch = 1 and ((angle < -140 and angle >= -180 ) or (angle >140 and angle <= 180))
Swipe = "LEFT"
endif
//swipe UP
if touch = 1 and (angle >= -140 and angle < -50)
swipe = "UP"
endif
//swipe RIGHT
if touch = 1 and ((angle >= -50 and angle <0) or (angle > 0 and angle < 45))
swipe = "RIGHT"
endif
//swipe DOWN
if touch = 1 and (angle < 140 and angle >= 45)
swipe = "DOWN"
endif
//reset swipe control when finger is released
if GetRawTouchReleased(1)
swipe = ""
endif
/*action will happen after finger is released
if GetRawTouchReleased(1)
select swipe
case "LEFT"
//do something
swipe = ""
endcase
case "RIGHT"
//do something
swipe = ""
endcase
case "UP"
//do something
swipe = ""
endcase
case "DOWN"
//do something
swipe = ""
endcase
endcase
endselect
*/
Print(swipe)
//Print(angle)
Sync()
loop