About Monkey 2 › Forums › Monkey 2 Programming Help › ANDROID – 3 Onscreen Buttons. LEFT-RIGHT & JUMP. How do I code it?
This topic contains 4 replies, has 2 voices, and was last updated by
Amon
1 year, 1 month ago.
-
AuthorPosts
-
March 3, 2018 at 10:00 pm #13848
I have 3 onscreen buttons in my game. 1 for going left, 1 for going right, and 1 for jumping. I’d like to be able to tap left or right buttons and also the jump button.
I can’t get anything to work. I need to be able to jump whilst going left or right.
Can any assistance be offered, please?
March 4, 2018 at 6:57 am #13851Have you opened the touchtest banana?
March 4, 2018 at 8:38 am #13852Yep. Still clueless.
March 5, 2018 at 10:08 pm #13887Here’s a short example. Note that there is Touch.FingerDown but also Touch.FingerPressed and Touch.FingerReleased like with the mouse button. (Touch.FingerPressure too on some devices!)
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends Window'seting up the buttons zones (using recti)Field butLeftRect:=New Recti (10,420,10+90,420+55)Field butRightRect:=New Recti (110,420,110+90,420+55)Field butJumpRect:=New Recti (510,420,510+90,420+55)Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()'Drawing the buttonscanvas.DrawRect(butLeftRect)canvas.DrawRect(butRightRect)canvas.DrawRect (butJumpRect)canvas.Color=Color.Blackcanvas.DrawText("LEFT",20,440)canvas.DrawText("RIGHT",120,440)canvas.DrawText("JUMP",520,440)'Buttons controlcanvas.Color=Color.Redcanvas.DrawText("finger0:"+Touch.FingerLocation(0)+" finger1: "+Touch.FingerLocation(1),10,10)For Local i:=0 To 9If butLeftRect.Contains(Touch.FingerLocation(i)) And Touch.FingerDown( i )canvas.DrawText("LEFT",20,100)EndifIf butRightRect.Contains(Touch.FingerLocation(i)) And Touch.FingerDown( i )canvas.DrawText("RIGHT",120,100)EndifIf butJumpRect.Contains(Touch.FingerLocation(i)) And Touch.FingerDown( i )canvas.DrawText("JUMP",520,100)EndifNextEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndMarch 7, 2018 at 2:45 am #13903Thank you. Will test now.
-
AuthorPosts
You must be logged in to reply to this topic.