Touchscreen Input (swipe)

Monkey Forums/Monkey Programming/Touchscreen Input (swipe)

Raul(Posted 2013) [#1]
Hello guys,

I am working at Heroes of Essran ( http://www.monkeycoder.co.nz/Community/posts.php?topic=5671 ) and I need to implement a swipe input method to scroll down my inventory and my heroes when creating the party. Both will be like a list.

I am thinking to detect the direction of the finger movement and then move the graphics for the list up or down. Any tips on how to do that correctly? Or is there another way?

Thank you


marksibly(Posted 2013) [#2]
Perhaps something like...

Import mojo

Class Swipe Extends App

	Field py:Float
	Field ty:Float
	Field vy:Float
	
	Method OnCreate()
		SetUpdateRate 60
	End
	
	Method OnUpdate()
		If TouchHit(0)
			py=TouchY(0)
			vy=0
		Else If TouchDown(0)
			vy=TouchY(0)-py
			py+=vy
		Else
			vy*=.9	'.9 is a 'drag' factor
		Endif
		ty+=vy
	End
	
	Method OnRender()
		Cls
		Translate 0,ty
		random.Seed=1234
		For Local i:=0 Until 100
			SetColor Rnd(256),Rnd(256),Rnd(256)
			DrawRect Rnd(DeviceWidth)-16,Rnd(DeviceHeight)-16,32,32
		Next
	End
End

Function Main()
	New Swipe
End



Raul(Posted 2013) [#3]
Hi Mark,

Yes. This is a good start. I am still not very satisfied by the movement of my list, but first I will have to implement the drag and drop from the list to another one..

Thanks again.