I have attached a project that is to be used as a template for cursor controls (I used the word cursor as not to confuse with pointer). Basically, I made a wrapper function around the Pointer and RawTouch controls. It works for both MultiTouch and Single Touch.
To scroll a playfield based upon user input, for both multi or single-touch
if GetCursorPressCount() = 1
if CanCursorScroll() = 1
REM UPDATE WORLD SCROLL VALUES
worldScrollX = worldScrollX - GetCursorScrollX()
worldScrollY = worldScrollY - GetCursorScrollY()
endif
endif
To see if a user swiped across the screen, for both multi or single-touch
Swap out 64 for your own values. A higher number means a swipe needs to be longer before it will be recognized
REM GET SWIPE VALUES
REM 1 MEANS USER SWIPED LEFT
REM -1 MEANS USER SWIPED RIGHT
REM 0 MEANS NO SWIPE OCCURED
if GetCursorSwipeX(64) = 1
message("Swiped Left")
endif
if GetCursorSwipeX(64) = -1
message("Swiped Right")
endif
REM 1 MEANS USER SWIPED UP
REM -1 MEANS USER SWIPED DOWN
REM 0 MEANS NO SWIPE OCCURED
if GetCursorSwipeY(64) = 1
message("Swiped Up")
endif
if GetCursorSwipeY(64) = -1
message("Swiped Down")
endif
To zoom in and out with two fingers, for multi-touch only
Swap out 300 to modify the speed of zoom. A higher number means a slower zoom
if GetCursorPressCount() = 2
if CanCursorZoom() = 1
spriteZoom = spriteZoom + GetCursorZoomDistance(300)
if spriteZoom < 0
spriteZoom = 0
endif
REM UPDATE SPRITE SCALE
SetSpriteScaleByOffset(1, spriteZoom, spriteZoom)
endif
endif
To get the current cursor - the default pointer on single touch machines, or an average of all touch coordinates on multi-touch screens
GetCursorX()
GetCursorY()
I'm sure there are improvements that could be made, but for basic multi-touch cross platform functionality in your applications - out of the box! - here you go.
If you use this code, please give me credit!
EDIT: Tweaked a small piece of code. Also, includes a demo for testing purposes. Delete the REMSTART and REMEND in the main.agc file to enable offset and zoom, but comment out the swiping code if you do so.
(I would not recommend using swipe with either offset and zoom)
Hi there. My name is Dug. I have just met you, and I love you.