Touch does not end when dragging offscreen or beyond image

Hello!

I setup a grid wherein the user touches one and moves through the grid.

The problem is that when the touch goes beyond the grid or beyond the screen, the touch does not end.

How do I fix this so the touch ends when it leaves the screen or leaves the grid?

Thanks for the help!

Regards,

John

Edit:

Do note that the grid is made up of individual square “buttons” that change color when the user drags their finger over them. [import]uid: 186198 topic_id: 32406 reply_id: 332406[/import]

@john272

One suggestion is that you keep track of the last touch object and as soon as you get a new touch that doesn’t match the old touch, send a fake event to the last object’s listener to end the prior touch. Then process the new touch.
Please see this code for clarification (click this sentence.)

You can see a video of this in action here: http://www.youtube.com/watch?v=B89v1QTDQdU

Lastly, get the sample as code or a downloadable Android/Fire/Nook binary here: http://developer.coronalabs.com/code/sskcorona

I hope this helps.

PS - The solution works only partially in the Simluator, but the end/cancel occurs fine on my test devices.

-Ed

[import]uid: 110228 topic_id: 32406 reply_id: 128892[/import]

@john272

One suggestion is that you keep track of the last touch object and as soon as you get a new touch that doesn’t match the old touch, send a fake event to the last object’s listener to end the prior touch. Then process the new touch.
Please see this code for clarification (click this sentence.)

You can see a video of this in action here: http://www.youtube.com/watch?v=B89v1QTDQdU

Lastly, get the sample as code or a downloadable Android/Fire/Nook binary here: http://developer.coronalabs.com/code/sskcorona

I hope this helps.

PS - The solution works only partially in the Simluator, but the end/cancel occurs fine on my test devices.

-Ed

[import]uid: 110228 topic_id: 32406 reply_id: 128892[/import]

Thanks for this, it helped a lot!

What I did was send an “ended” event when the x and y goes beyond the screen or beyond the bounds of the grid bunch.:smiley:

for reference:

[lua]if (event.x < threshold or event.x > _W-threshold) or (event.y < (_H/5 - sqr_size/2 + threshold ) or
event.y > ((_H/5 + (sqr_size * dimensions - sqr_size/2) - threshold )) ) then
–print(“sulod”)
event.target = lastTarget
event.phase = “ended”
event.x = _W/2 – put the x and y coordinates somewhere else
event.y = _H/2 – to prevent an infinite loop
currentStage.lastTarget = nil
self:touch( event )
end[/lua]

John [import]uid: 186198 topic_id: 32406 reply_id: 130003[/import]

Thanks for this, it helped a lot!

What I did was send an “ended” event when the x and y goes beyond the screen or beyond the bounds of the grid bunch.:smiley:

for reference:

[lua]if (event.x < threshold or event.x > _W-threshold) or (event.y < (_H/5 - sqr_size/2 + threshold ) or
event.y > ((_H/5 + (sqr_size * dimensions - sqr_size/2) - threshold )) ) then
–print(“sulod”)
event.target = lastTarget
event.phase = “ended”
event.x = _W/2 – put the x and y coordinates somewhere else
event.y = _H/2 – to prevent an infinite loop
currentStage.lastTarget = nil
self:touch( event )
end[/lua]

John [import]uid: 186198 topic_id: 32406 reply_id: 130003[/import]