I’ve played a little with the code and I’m not sure multitouch is really broken. Running Mike test program showed an error when displaying the number of previousTouches. The problem is event.previousTouches is a table that is “nil” when only one finger is touching the display. This generated a run-time error (can’t return the count of a nil object). I fixed that problem and the test code acts a lot better. I was able to detect up to four fingers on the display.
I modified the code adding a touch counter and event phase. I’m not sure the multitouch is 100% working because I haven’t looked at all the event being generated. I commented out the original code that was causing the errors.
Tom
[code]
– activate multitouch
system.activate( “multitouch” )
local tPrevious= 0
local touchCnt = 0 – total number of touches
txtfps = display.newText( “fps:99”, 240, 20, “Verdana-Bold”, 16 )
txtfps:setTextColor( 255,255,255 )
txtTouch = display.newText( " ctouches: 99", 40, 20, “Verdana-Bold”, 16 )
txtTouch:setTextColor( 255,255,255 )
txtTouch.text = " ctouches: "…0
txtTouchp = display.newText( " ptouches: 99", 40, 60, “Verdana-Bold”, 16 )
txtTouchp:setTextColor( 255,255,255 )
txtTouchp.text = " ptouches: "…0
txtTouchc = display.newText( “touch cnt: 0”, 40, 100, “Verdana-Bold”, 16 )
txtTouchc:setTextColor( 255,255,255 )
txtTouchType = display.newText( “previousTouch Type: nil”, 45, 400, “Verdana-Bold”, 16 )
txtTouchType:setTextColor( 255,255,255 )
txtTouchPhase = display.newText( “touch Phase: begin”, 45, 440, “Verdana-Bold”, 16 )
txtTouchPhase:setTextColor( 255,255,255 )
local finish = function(target)
target.parent:remove( target )
end
local mRandom = math.random
– create a table listener object for the bkgd image
function onTouch( event )
–local result = true
–local phase = event.phase
–print (event.phase)
– when multitouch is active, the event will contain an array of
– all touch events that have changed since the last touch event
– these should all share the same phase
local touches = event.touches
– when multitouch is active, the event will contain an array of
– all touches that are still touching the screen from previous events
local previousTouches = event.previousTouches
touchCnt = touchCnt + 1
–[[
txtTouch.text = “ctouches:”…#touches
txtTouchp.text = “ptouches:”…#previousTouches – *** This will cause error if “nil” ***
–]]
txtTouch.text = "ctouches: " … tostring(type(touches) ~= “nil” and #touches)
txtTouchp.text = "ptouches: " … tostring(type(previousTouches) ~= “nil” and #previousTouches)
txtTouchc.text = "touch cnt: " … touchCnt
txtTouchType.text = "previousTouches Type: " … type(event.previousTouches)
txtTouchPhase.text = "touch Phase: " … event.phase
– for i = 1,#touches do
– spr = display.newCircle(touches[i].x, touches[i].y, 10 )
– spr:setFillColor(255,0,255,255)
– transition.to(spr,{time=100, x=touches[i].x+mRandom(-40,40), y=touches[i].y+mRandom(-40,40), onComplete=finish})
– end
– for i = 1,#previousTouches do
– spr = display.newCircle(previousTouches[i].x, previousTouches[i].y, 10 )
– spr:setFillColor(0,0,255,255)
– transition.to(spr,{time=100, x=previousTouches[i].x+mRandom(-40,40), y=previousTouches[i].y+mRandom(-40,40), onComplete=finish})
– end
end
local onFrame = function(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
txtfps.text = "fps: "…tDelta
collectgarbage(“collect”)
end
– register table listener
Runtime:addEventListener( “touch”, onTouch )
Runtime:addEventListener( “enterFrame”, onFrame )
[/code] [import]uid: 6119 topic_id: 1119 reply_id: 2881[/import]