Hey,
I have two images that need to be pressed at the same time for a function to activate. I set a counter, and the multi-touch is working, but the function does not activate when the counter = 2. Code:
[code]
function eventTouch(event)
if(event.phase == “began”) then
text1.text = “Hold”
counter = counter + 1
print(counter)
end
if(event.phase == “ended”) then
text1.text = “Press both images at the same time”
counter = counter - 1
print(counter)
end
end
image1:addEventListener(“touch”, eventTouch)
image2:addEventListener(“touch”, eventTouch)[/code]
And that’s the function: [code]
local function onTimer(event)
if flag then
print(“The button was pressed for 4 seconds”)
local event = {}
event.phase = “ended”
image1:dispatchEvent( event )
director:changeScene(“scene2”)
else
end
end
local function onTouch(event)
if (counter == 2) then
flag = true
timerHandle = timer.performWithDelay(4000,onTimer)
else
flag = false
timer.cancel(timerHandle)
timerHandle = nil
end
end[/code]
So, explaining: only once the user starts pressing both images, a timer starts. And only if he keeps holding it for 4 seconds, the scene will change. Otherwise, it will cancel the timer.
Any thoughts?
Appreciate it!
[import]uid: 95495 topic_id: 20787 reply_id: 320787[/import]

