issue using touch event

this is my code for a slider control
most times it works fine but some times when i move the slider it moves like its suppose to but when you release the control it seems to skip the ended phase

[blockcode]
function fnMoveControl(event)

if event.phase == “began” then

elseif event.phase == “moved” then
event.target.y = math.min( 870, math.max( 290, event.y) )
elseif event.phase == “ended” then
ctrl[1] = math.floor( ( ( 870 - control[1].y ) / 58 ) + 0.5 )
ctrl[2] = math.floor( ( ( 870 - control[2].y ) / 58 ) + 0.5 )
print( ctrl[1]…","…ctrl[2] )
fnSetControl()
end
end
[/blockcode]
[import]uid: 7911 topic_id: 13523 reply_id: 313523[/import]

figured it out

since my object only moves in the y direction, if your finger moves off the object in the x direction the ended phase doesnt happen the cancelled phase does. so to fix it i copied my ended phase to a cancelled phase also that way it works if your finger moves off the object [import]uid: 7911 topic_id: 13523 reply_id: 49641[/import]

you may use
if event.phase == “ended” or event.phase ==“cancelled”. [import]uid: 71210 topic_id: 13523 reply_id: 49679[/import]

yeah i made this change when i went back though doing some optimizing. although i found out that although this cut down on the problem it didnt completely go away it still skips the ended and cancelled phases if you go too far in the y or x direction [import]uid: 7911 topic_id: 13523 reply_id: 49681[/import]

sorry for the delay in replying …was busy…its national day here in singapore… went to see the parade… :slight_smile:

the problem is with setting the focus…once you click on the object and move the touch outside the object the ended phase of the object wot’ register.
try this code. let me know how it works
[lua]local ctrl ={}
function fnMoveControl(event)

if event.phase == “began” then
display.getCurrentStage():setFocus( event.target )
event.target.isFocus = true
elseif event.target.isFocus then
if event.phase == “moved” then
event.target.y = math.min( 200, math.max( 80, event.y) )
elseif event.phase == “ended” then
print(“ended”)
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
elseif event.phase == “canceled” then
print(“cancelled”)
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
end

local ball = display.newCircle(100,100,20)
ball:addEventListener(“touch”,fnMoveControl)[/lua] [import]uid: 71210 topic_id: 13523 reply_id: 49714[/import]

thanks renvis that worked perfect [import]uid: 7911 topic_id: 13523 reply_id: 49837[/import]

:slight_smile: good to know that it worked.
Renjith
www.technowand.com [import]uid: 71210 topic_id: 13523 reply_id: 49839[/import]