Simple Movement?

Monkey Targets Forums/Android/Simple Movement?

Xyloman(Posted 2012) [#1]
Hi i am really new to monkey and i cant figure out how to set touch inputs for android and how to make them move sprites or a shape on the screen.

Please Help.


therevills(Posted 2012) [#2]
How do you want your touch inputs to move (shape?) a sprite?


Xyloman(Posted 2012) [#3]
Left right and jump or just left and right for now.


therevills(Posted 2012) [#4]
OK.. You can do that a few ways, do you want onscreen buttons or do you want to swipe your sprites to move them?

If you just want the buttons you can just use the TouchDown commands and just check where the touch occurs.


Capn Lee(Posted 2012) [#5]
Method TouchDetect:Bool(x:Int, y:Int, w:Int, h:Int)
	For Local i:Int = 0 To 5
		If TouchHit(i)
			If TouchX(i) >= x - pressdistance
				If TouchX(i) <= x + w + pressdistance
					If TouchY(i) >= y - pressdistance
						If TouchY(i) <= y + h + pressdistance
							Return True
						EndIf
					EndIf
				EndIf
			EndIf
		EndIf
	Next
	Return False
End

EDIT: made it seperate if statements so as not to make it one line, it made the thread look bad :)

There is a method you can call to detect where a touch has occured, I have an int called pressdistance that is basically a buffer zone around the button that would also count as a hit. I tend to keep it at around 32

It's probably not the neatest way to do it but I find it works fine
here is an example of it being called

Method FDLGameCheck:Int()
	If TouchDetect(3 * 32, 9 * 32, 32, 48) Then turncommand = gmUp
	If TouchDetect(2 * 32 + 16, 8 * 32 + 16, 64, 16) Then turncommand = gmUp
	If TouchDetect(5 * 32 - 16, 11 * 32, 48, 32) Then turncommand = gmRight
	If TouchDetect(6 * 32, 10 * 32 + 16, 16, 64) Then turncommand = gmRight
	If TouchDetect(3 * 32, 13 * 32 - 16, 32, 48) Then turncommand = gmDown
	If TouchDetect(2 * 32 + 16, 14 * 32, 64, 16) Then turncommand = gmDown
	If TouchDetect(1 * 32, 11 * 32, 48, 32) Then turncommand = gmLeft
	If TouchDetect(16, 10 * 32 + 16, 16, 64) Then turncommand = gmLeft
	Return 0
End


hope that helps