Ok, so I didn't really know how multitouch worked. I decided to mess with it and learn a little. This might help you understand how to use multitouch.
// Project: Two Buttons and multitouch
// Created: 2015-04-14
// set window properties
SetWindowTitle( "multitouch" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 0, 0, 1, 1 )
// set print properties
SetPrintColor( 255, 255, 0 )
SetPrintSize( 18 )
global touch_state as integer
global touch_state_string as string = "Using Start Positions"
createEverything()
do
// exit app using escape or back button
if GetRawKeyPressed(27) = 1
end
endif
hitCheck()
Sync()
loop
function hitCheck()
Print( ScreenFPS() )
toggleButton()
print("------------------- " + touch_state_string)
// use a case/select to toggle between states
select touch_state
case 0:
startTouchPos()
endcase
case 1:
currentTouchPos()
endcase
endselect
// print all the information
// print("first: " + str(GetRawFirstTouchEvent(1)))
// print("next: " + str(GetRawNextTouchEvent()))
print("Number of Touch Events: " + str(GetRawTouchCount(1)))
if GetRawTouchCount(1) > 0
for i = 1 to GetRawTouchCount(1)
print("")
print("----- Event " + str(i) + " -----")
if GetRawTouchType(i) = 1
print("Event Type: Short")
elseif GetRawTouchType(i) = 2
print("Event Type: Hold")
elseif GetRawTouchType(i) = 3
print("Event Type: Drag")
endif
print("Start Position: [" + str(GetRawTouchStartX(i)) + ", " + str(GetRawTouchStartX(i)) + "]" )
print("Current Position: [" + str(GetRawTouchCurrentX(i)) + ", " + str(GetRawTouchCurrentY(i)) + "]" )
next i
endif
endfunction
function toggleButton()
// code that toggles that state variable
// check if first touch event hits sprite 3
if GetSpriteHitTest(3, ScreenToWorldX(GetRawTouchStartX(1)), ScreenToWorldY(GetRawTouchStartY(1)) ) and touch_state = 0 and GetRawTouchReleased(1)
SetSpriteColor(1, 0, 255, 0, 255)
touch_state = 1
touch_state_string = "Using Current Positions"
elseif GetSpriteHitTest(3, ScreenToWorldX(GetRawTouchStartX(1)), ScreenToWorldY(GetRawTouchStartY(1)) ) and touch_state = 1 and GetRawTouchReleased(1)
SetSpriteColor(1, 255, 0, 0, 255)
touch_state = 0
touch_state_string = "Using Start Positions"
endif
endfunction
function startTouchPos()
// check whether the touch event start location hits sprites
// check sprite 1 if the first or second touch event hits
if GetSpriteHitTest(1, ScreenToWorldX(GetRawTouchStartX(1)), ScreenToWorldY(GetRawTouchStartY(1)) )
SetSpriteColor(1, 0, 255, 0, 255)
elseif GetSpriteHitTest(1, ScreenToWorldX(GetRawTouchStartX(2)), ScreenToWorldY(GetRawTouchStartY(2)) )
SetSpriteColor(1, 0, 255, 0, 255)
else
SetSpriteColor(1, 255, 0, 0, 255)
endif
// check sprite 2 if the first or second touch event hits
if GetSpriteHitTest(2, ScreenToWorldX(GetRawTouchStartX(1)), ScreenToWorldY(GetRawTouchStartY(1)) )
SetSpriteColor(2, 0, 255, 0, 255)
elseif GetSpriteHitTest(2, ScreenToWorldX(GetRawTouchStartX(2)), ScreenToWorldY(GetRawTouchStartY(2)) )
SetSpriteColor(2, 0, 255, 0, 255)
else
SetSpriteColor(2, 255, 0, 0, 255)
endif
endfunction
function currentTouchPos()
// check whether the touch event current location hits sprites
// check sprite 1 if the first or second touch event hits
if GetSpriteHitTest(1, ScreenToWorldX(GetRawTouchCurrentX(1)), ScreenToWorldY(GetRawTouchCurrentY(1)) )
SetSpriteColor(1, 0, 255, 0, 255)
elseif GetSpriteHitTest(1, ScreenToWorldX(GetRawTouchCurrentX(2)), ScreenToWorldY(GetRawTouchCurrentY(2)) )
SetSpriteColor(1, 0, 255, 0, 255)
else
SetSpriteColor(1, 255, 0, 0, 255)
endif
// check sprite 2 if the first or second touch event hits
if GetSpriteHitTest(2, ScreenToWorldX(GetRawTouchCurrentX(1)), ScreenToWorldY(GetRawTouchCurrentY(1)) )
SetSpriteColor(2, 0, 255, 0, 255)
elseif GetSpriteHitTest(2, ScreenToWorldX(GetRawTouchCurrentX(2)), ScreenToWorldY(GetRawTouchCurrentY(2)) )
SetSpriteColor(2, 0, 255, 0, 255)
else
SetSpriteColor(2, 255, 0, 0, 255)
endif
endfunction
function createEverything()
// create all sprites and set their properties
for i = 1 to 3
CreateSprite(i, 0)
if i < 3
SetSpriteSize(i, 200, 200)
SetSpriteOffset(i, GetSpriteWidth(i) / 2, GetSpriteHeight(i) / 2)
SetSpriteColor(i, 255, 0, 0, 255)
else
SetSpriteSize(i, 100, 100)
SetSpriteOffset(i, GetSpriteWidth(i) / 2, GetSpriteHeight(i) / 2)
SetSpriteColor(i, 255, 0, 0, 255)
endif
next
SetSpritePositionByOffset(1, 312, 384)
SetSpritePositionByOffset(2, 712, 384)
SetSpritePositionByOffset(3, 60, 708)
endfunction