Is there a TouchUp check?

Monkey Forums/Monkey Programming/Is there a TouchUp check?

ondesic(Posted 2012) [#1]
I did a search for TouchUp but didn't find what I need. I see there is a TouchDown and TouchHit. How can I determine when a TouchUp has occured?


Gerry Quinn(Posted 2012) [#2]
I guess you could record whether touch(n) was down on any update and then record a TouchUp on the first update when it is no longer down.

Same as drag-release, which I think has been discussed.


NoOdle(Posted 2012) [#3]
I quickly knocked up this example to show a way of identifying more touches. If you run the code in htlm5 and click and drag around it will print showing what its recognising. it can detect Down, Moved, Up and Up Inside. Hopefully this should help you implement a function, if you get stuck let me know. The code doesn't check for more than 1 touch so that will need to be considered...

[monkeycode]
import mojo


'/ checks if two values are equal to each other +/- tolerance
Function IsEqual : Bool( a : Float, b : Float, tolerance : Float = 0.0 )
Return Abs( a - b ) <= tolerance
End Function


Class MyApp Extends App


Field touching : Bool = False
Field touchXA : Int
Field touchYA : Int

Field touchXB : Int
Field touchYB : Int



Method OnCreate()

SetUpdateRate( 60 )

End Method



Method OnUpdate()


'if touching screen
If TouchDown() <> 0

'if this is a new touch
If touching = False

'grab initial touch location
touchXA = TouchX()
touchYA = TouchY()

'active touching
touching = True

'we are touching
Else

'grab current touch location
touchXB = TouchX()
touchYB = TouchY()

'Check the the current touch location is still similar to the first touch location
If IsEqual( touchXA, touchXB, 5.0 ) And IsEqual( touchYA, touchYB, 5.0 )

'fire touch down
Print "Touch Down"

'mouse has moved while still being pressed
Else

'fire touch
Print "Touch Moved"

Endif

Endif

'if not touching the screen
Else

'if we where just touching the screen
If touching = True

'reset touching
touching = False

'Check the the current touch location is still similar to the first touch location
If IsEqual( touchXA, touchXB, 5.0 ) And IsEqual( touchYA, touchYB, 5.0 )

'touch has not move from initial spot
Print "Touch Up Inside"

Else

'touch has moved from initial spot
Print "Touch Up"

Endif


Endif

Endif

End Method



Method OnRender()
Cls 255, 255, 255


End Method


End Class


Function Main()
New MyApp()
End Function

[/monkeycode]