Touch Event listener Problem occurence

Sometime phase of the touch event is not going to “ended” phase when touch is released.What could be the possible reasons?

Code:

function cometoscreen(event) 

local pausegp=event.target

local phase=event.phase

if “began”==phase then 

– display.getCurrentStage():setFocus(pausegp)

– pausegp.isFocus=true  

initx=event.x 

inity=event.y  

elseif “moved”==phase then

pausegp.x =event.x

pausegp.y=0   

–planet_red.x=planet_red+pausegp.x 

a=event.x-initx 

print("a<40 if "…a)   

if(a<=0 ) then 

–pausegp:removeEventListener(“touch”,cometoscreen)

transition.to(pausegp,{time=200,x=display.contentWidth*0.5-640})    

  

end      

if (a>150) then 

transition.to(pausegp,{time=200,x=display.contentWidth*0.5-460,onComplete=function() 

pausegp:addEventListener(“touch”,gobacktosameplace) 

pausegp:removeEventListener(“touch”,cometoscreen)   

gunTurret:removeEventListener(“touch”,rotateObj)

satelite1:removeEventListener(“touch”, rotateSat)

circle:removeEventListener(“tap”,engage_shoot)  

  

end})   

display.getCurrentStage():setFocus( nil )

pausegp.isFocus=false  

end

elseif “ended”==phase or “cancelled”==phase then 

print(“yoyoyo”) 

if(a<=40 ) then 

transition.to(pausegp,{time=100,x=display.contentWidth*0.5-640,onComplete=function() 

display.getCurrentStage():setFocus( nil )

pausegp.isFocus=false  

end})    

end  

  

if (a>40) then 

transition.to(pausegp,{time=200,x=display.contentWidth*0.5-460,onComplete=function() 

pausegp:addEventListener(“touch”,gobacktosameplace) 

  

end})   

display.getCurrentStage():setFocus( nil )

pausegp.isFocus=false  

pausegp:removeEventListener(“touch”,cometoscreen)   

gunTurret:removeEventListener(“touch”,rotateObj)

satelite1:removeEventListener(“touch”, rotateSat)

circle:removeEventListener(“tap”,engage_shoot) 

end

end

return true

end

Is this happening on simulator or on device?

It can happen sometimes in simulator if you go offscreen with your mouse, but that can’t happen on device so it’s ok.

Daniel

Problem is occur in both simulator and device.

But when we swipe  that image,then it sometimes stop in middle and didn’t call event.phase==“ended”. And it happening on screen not off-screen.

Are there 2 objects overlapping each other which both have touch listeners? It’s possible for a second object to “steal” the touch event from the first so that only some phases will be registered on the first object.  

Try adding:

return true

to the bottom of your touch function.

local myTouchFunction(event) if event.phase == "began" then --do something elseif event.phase == "moved" then --do something else elseif event.phase == "ended" then --stop doing stuff end return true end

Already tried but still problem not solved.

Is this happening on simulator or on device?

It can happen sometimes in simulator if you go offscreen with your mouse, but that can’t happen on device so it’s ok.

Daniel

Problem is occur in both simulator and device.

But when we swipe  that image,then it sometimes stop in middle and didn’t call event.phase==“ended”. And it happening on screen not off-screen.

Are there 2 objects overlapping each other which both have touch listeners? It’s possible for a second object to “steal” the touch event from the first so that only some phases will be registered on the first object.  

Try adding:

return true

to the bottom of your touch function.

local myTouchFunction(event) if event.phase == "began" then --do something elseif event.phase == "moved" then --do something else elseif event.phase == "ended" then --stop doing stuff end return true end

Already tried but still problem not solved.