Some lines and Angles, also simple Drag'n'Drop, for one test Sprite. No pinching, no rotating
// Project: FLmultiTouch_2019
// Created: 2019-03-15
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "FLmultiTouch_2019" )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 120, 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
img as integer[10]
spr as integer[10] // debug sprites
Touch as integer[10]
spx as integer[10] // Sprite, which can be manipulated
stx as integer[10] // for String-Texts
fontID = 1
LoadFont(fontID,"Arial")
StartGPSTracking()
imgx = LoadImage("Button_FL.png") // "Button.png" is reserved!
spx[1] = CreateSprite(imgx)
SetSpriteScale(spx[1],2.5,1.5)
SetSpritePosition(spx[1],30,30)
For i=1 to 10
img[i] = CreateImageColor(i*20,250-i*20,255,255)
spr[i] = CreateSprite(img[i])
stx[i]=CreateText("")
SetTextFont(stx[i],fontID)
SetTextSize(stx[i],32)
SetSpriteScale(spr[i], 100, 100)
SetSpritePosition(spr[i],Random(0,10)*100, Random(0,10)*60)
Next
do
Print( Str(ScreenFPS(),2) )
Print(GetRawTouchTime( GetRawFirstTouchEvent(1)))
Print(GetRawTouchCount(0))
RTE= GetRawFirstTouchEvent(1)
Touch[1] = RTE
Touch[0] = RTE
//While NTE<>0
For t=2 to 10
NTE= GetRawNextTouchEvent()
Touch[t]=NTE
If NTE<>0
Touch[0]=NTE
Else
EndIf
Next
//EndWhile
For t=0 to 9
// If Touch[t+1]=0
// DrawLine(GetRawTouchCurrentX(Touch[t]),GetRawTouchCurrentY(Touch[t]),GetRawTouchCurrentX(Touch[0]),GetRawTouchCurrentY(Touch[0]),255,255,255)
if t>-1
SetSpritePosition(spr[t+1],GetRawTouchCurrentX(Touch[t+1])-GetSpriteWidth(spr[t+1])/2,GetRawTouchCurrentY(Touch[t+1])-GetSpriteHeight(spr[t+1])/2)
endif
// Else
If Touch[t+1]<>0
XX = GetRawTouchCurrentX(Touch[t])
YY = GetRawTouchCurrentY(Touch[t])
X2 = GetRawTouchCurrentX(Touch[t+1])
Y2 = GetRawTouchCurrentY(Touch[t+1])
/*
XL = Abs(Abs(XX)-Abs(X2)) // optimisation possible
YL = Abs(Abs(YY)-Abs(Y2))
*/
XL = XX-X2
YL = YY-Y2
alpha# = atan(1.0*YL/XL)
DrawLine(XX,YY,X2,Y2,255,255,255)
SetTextPosition(stx[t+1],(XX+X2)/2-30,(YY+Y2)/2-30)
SetTextString(stx[t+1],Str(alpha#,2)+chr(10)+Str(sqrt(xl^2+yl^2),2)) // not all values are allowed for tan!!!
// Winkel-Funktion, AnKathete / GegenKathete = Tangens(Alpha)
EndIf
// EndIf
Next
If GetSpriteHitTest(spx[1],GetRawTouchCurrentX(Touch[1]), GetRawTouchCurrentY(Touch[1])) and GetSpriteHitTest(spx[1],GetRawTouchLastX(Touch[1]), GetRawTouchLastY(Touch[1]))
DX = 10
// Problem: Das letzte Touch-Event auf dem Objekt, muss das Offset wissen, das Objekt darf nicht springen
If (GetRawTouchTime(Touch[1])<0.1) // or (GetRawTouchCurrentX(spx[1])+DX>GetRawTouchLastX(Touch[1])) or (GetRawTouchCurrentY(spx[1])+DX>GetRawTouchLastY(Touch[1])) // verursacht Fehler, wenn erster Finger entfernt wird
// Without, the Sprite drifts away on longer drag-distance
// maybe some rounding error somewhere
//If GetRawTouchType(
XDivC = ScreenToWorldX(GetRawTouchCurrentX(Touch[1])-GetSpriteX(spx[1])) // irgendwas mit ScreenToWorldX
YDivC = ScreenToWorldY(GetRawTouchCurrentY(Touch[1])-GetSpriteY(spx[1]))
XDivL = ScreenToWorldX(GetRawTouchLastX(Touch[1]))-GetSpriteX(spx[1])
YDivL = ScreenToWorldY(GetRawTouchLastY(Touch[1]))-GetSpriteY(spx[1])
endif
Print("Sprite Hit " + Str(XDivL)+":"+ Str(YDivL))
Print("Sprite Hit " + Str(XDivC)+":"+ Str(YDivC))
//SetSpritePosition(spx[1],GetRawTouchLastX(Touch[1])-XDiv,GetRawTouchLastY(Touch[1])-YDiv)
SetSpritePosition(spx[1],GetRawTouchCurrentX(Touch[1])-XDivL,GetRawTouchCurrentY(Touch[1])-YDivL)
// Some error in this code, distance is not constant
EndIf
// how to pinch / zoom? Maybe rotate?
/*
Print(GetAccelerometerExists())
Print("AccelX : " + str( GetRawAccelX() ))
Print("AccelY : " + str( GetRawAccelY() ))
Print("AccelZ : " + str( GetRawAccelZ() ))
Print("----")
Print(GetRawGyroVelocityX())
Print(GetRawGyroVelocityY())
Print(GetRawGyroVelocityZ())
Print("----")
Print(GetRawMagneticX())
Print(GetRawMagneticY())
Print(GetRawMagneticZ())
Print("----")
Print(GetRawGPSAltitude())
Print(GetRawGPSLatitude())
Print(GetRawGPSLongitude())
*/
Sync()
loop