Button multi-touch
Monkey Forums/Monkey Programming/Button multi-touch
| ||
| I'm working on perfecting my button code. I only want to support two fingers. My button code is working fine with single-touch, but I want to expand it. Here is what I have so far (imageless) The Update function is what I am working on right now. So, I have added a for loop to look at two touch events. Would I need to make clickHold, clicked, and down into arrays? I am trying to think of a better way and am interested in how others would do it. Hopefully this thread will help someone else in the future as well. Thank you |
| ||
That's how I do it in my control class, using up to 5 touch events:
_numberOfTouchEvents = 0
For Local i:Int = 0 To 4
_currentTouchX[i] = Float( TouchX(i) ) / gScaleRatio
_currentTouchY[i] = Float( TouchY(i) ) / gScaleRatio
If( TouchDown(i) And _isTouchPressed[i] = False )
_isTouchPressed[i] = True
_isTouchReleased[i] = False
_TouchPressedX[i] = _currentTouchX[i]
_TouchPressedY[i] = _currentTouchY[i]
Else If( Not TouchDown(i) And _isTouchPressed[i] = True )
_isTouchPressed[i] = False
_isTouchReleased[i] = True
_TouchReleasedX[i] = _currentTouchX[i]
_TouchReleasedY[i] = _currentTouchY[i]
Else If( TouchDown(i) And _isTouchPressed[i] = True )
_numberOfTouchEvents += 1
End If
Next
I use the number of touch events for zooming for instance:
'Check for multi touch events
If( _numberOfTouchEvents = 2 )
If( _lastDistanceBetweenTwoTouchPoints < 0.0 )
_lastDistanceBetweenTwoTouchPoints = GetDistSq( _currentTouchX[0], _currentTouchY[0], _currentTouchX[1], _currentTouchY[1] )
End If
'Zooming
Local sqDist:Float = GetDistSq( _currentTouchX[0], _currentTouchY[0], _currentTouchX[1], _currentTouchY[1] )
_zoomSpeed = sqDist - _lastDistanceBetweenTwoTouchPoints
_lastDistanceBetweenTwoTouchPoints = sqDist
gCurrentZoom += _zoomSpeed / 200000.0
If( gCurrentZoom < MIN_ZOOM ) Then gCurrentZoom = MIN_ZOOM
If( gCurrentZoom > MAX_ZOOM ) Then gCurrentZoom = MAX_ZOOM
Else
_lastDistanceBetweenTwoTouchPoints = -1.0
End If
|
| ||
| Ah yeah, I don't really care about the count so much but that makes sense. I'm just trying to support two buttons being pressed. So the user can press left/right and also jump at the same time. |
| ||
| So, I changed my clicked, down, and clickHold variables to arrays. It is working for the most part, but still isn't perfect yet. Sometimes when I hold both buttons down they will both release without me lifting my fingers. Not sure what is causing that. |
| ||
| One issue looks to be if you press and hold with the 1st finger, press and hold with the 2nd finger, and then lift the 1st finger it doesn't think the 2nd finger is down still. Still looking to define any other issues. Things are definitely not perfect :( |
| ||
| Hmm the odd behavior only seems to be occurring on older versions of Android (2.3.4) and not newer versions of Android (4.4.2). No idea why :S Could anyone else please test this? Also interested on how it looks on ios. Also, if would be great if anyone could let me know if they see any flaws in the logic. Thank you |
| ||
| It may be related to the device. Older devices have broken multitouch with "crossing axis" problems |
| ||
| Thanks Nobuyuki :) |