About Monkey 2 › Forums › Monkey 2 Programming Help › TouchScreen – Multi-Touch.
This topic contains 1 reply, has 2 voices, and was last updated by
APC
1 year, 2 months ago.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
January 30, 2018 at 11:12 pm #13372
Can anyone provide a multi-touch example?
I basically need to be able to press on the touchscreen the left and right arrows of my game and also be able to tap the jump button on the screen to jump at the same time.
I checked the example in bananas but I’m way off understanding how it does what it does. Is there an easier/better example?
Thanks.
January 31, 2018 at 10:00 am #13388Amon,
There is a simple example in the Monkey2 bananas folder called touchtest.
You can detect more than 2 fingers touching the screen.
Here is the code
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField gesturing:BoolField g0:AffineMat3fMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod GestureMatrix:AffineMat3f( p0:Vec2f,p1:Vec2f )Local d:=p1-p0,r:=-ATan2( d.y,d.x ),s:=d.LengthReturn New AffineMat3f().Translate( p0 ).Rotate( r ).Scale( s,s )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()Local gmatrix:=New AffineMat3fIf Not gesturing And Touch.FingerDown( 0 ) And Touch.FingerDown( 1 )'begin gesturingg0=-GestureMatrix( Touch.FingerLocation( 0 ),Touch.FingerLocation( 1 ) )gesturing=TrueEndifIf gesturing And Touch.FingerDown( 0 ) And Touch.FingerDown( 1 )'gesturing...gmatrix=GestureMatrix( Touch.FingerLocation( 0 ),Touch.FingerLocation( 1 ) ) * g0Else If gesturing'end gesturinggesturing=FalseEndifcanvas.PushMatrix()canvas.Matrix=gmatrixFor Local i:=0 Until 8For Local j:=0 Until 8canvas.Color= (i~j)&1 ? Color.Yellow Else Color.Greycanvas.DrawRect( New Recti( i*Width/8,j*Height/8,(i+1)*Width/8,(j+1)*Height/8 ) )NextNextcanvas.PopMatrix()canvas.Color=Color.Whitecanvas.Scale( 2,2 )For Local i:=0 Until 10canvas.DrawText( "Finger "+i+": down="+Int( Touch.FingerDown(i) )+", location="+Touch.FingerLocation(i)+", pressure="+Touch.FingerPressure(i),0,i*canvas.Font.Height )NextEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.