TGC Codebase Backup



AGK Touch Screen Detecting by ApkGames.Guru

19th Nov 2014 2:30
Summary

This short routine will allow you to trap diagonal touch movements on your touch screen and can be used within your apps.



Description

This short routine will allow you to trap diagonal touch movements on your touch screen and can be used within your apps.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    global SwipeTime , SwipeLeft , SwipeRight , SwipeUp , SwipeDown
 SetVirtualResolution(480,800) : SetDisplayAspect(480/800)

do
  test=GetSwipe(0.1,30)
  if test= 0 then flag$=""
  if test= 1 then flag$="Left"
  if test= 2 then flag$="Right"
   if test= 4 then flag$="Up"
  if test= 5 then flag$="Left/Up"
  if test= 6 then flag$="Right/Up"
  if test= 8 then flag$="Down"
  if test= 9 then flag$="Left/Down"
   if test=10 then flag$="Right/Down"
  If GetRawKeyPressed(27)=1 then END
  Print(Flag$)
  Sync()
loop

function GetSwipe(t#,s)
  output=0
  If GetPointerState()=0 then SwipeTime=Timer()+t#
   If GetPointerPressed()=1 then SwipeRight=GetPointerX()+s
  If GetPointerPressed()=1 then SwipeLeft=GetPointerX()-s
  If GetPointerPressed()=1 then SwipeDown=GetPointerY()+s
  If GetPointerPressed()=1 then SwipeUp=GetPointerY()-s
   If GetPointerState()=1 and SwipeTime<Timer()
    If SwipeLeft>GetPointerX()
      SwipeTime=0 : output=output+1
    EndIf
    If SwipeRight<GetPointerX()
      SwipeTime=0 : output=output+2
    EndIf
     If SwipeUp>GetPointerY()
      SwipeTime=0 : output=output+4
    EndIf
    If SwipeDown<GetPointerY()
      SwipeTime=0 : output=output+8
    EndIf
  endif
endfunction output