click events that go offscreen in simulator

When I’m using the simulator, if I drag the mouse off the bounds of the simulator screen, it is still considered a “moved” phase touch event, and then when I eventually release the mouse, the (x,y) of the “ended” event are way off screen.

I’m assuming that this would be impossible with a real device, since if you’re using an iphone or something wouldn’t the “ended” phase of the touch event would fire as soon your finger was dragged off the bounds of the screen?

This is problematic for testing my game. I can code around it (i.e. try to translate the event(x,y) into an appropriate x,y on the screen), but it seems a little silly to add custom code that is only relevant to the simulator.

Anyone have any know a good way to deal with this issue?
[import]uid: 115687 topic_id: 20449 reply_id: 320449[/import]

why don’t you have a bit of code in the emded phase, that checks to see if the event.x and event.y is greater than the screen if it is then make the event.x the border of the screen… also will need to to check to see if it is less than the screen

something like this

if event.x > display.contentWidth then

event.x = display.contentWidth
end

This way if the mouse goes over the bounds of the screen, it is reset back to the bounds of the screen [import]uid: 67619 topic_id: 20449 reply_id: 80099[/import]

Yeah, I can do something like that. I’ll have to do something a wee bit more complicated because I’m trying to track the relationship between the place that was touched and the place where it’s released (and if I just clamp the x,y to the bounds of the screen, it would change the angle of the line between the touch and release points). But I can work something out.

Was hoping there was some feature of the simulator I missed that would force a touch end if the mouse gets dragged offscreen or something nice and simple like that :slight_smile:

thanks! [import]uid: 115687 topic_id: 20449 reply_id: 80102[/import]

no probs…

if the angle is important, and all you need is the touch point at the boundary level, you might have to do some maths… with line intersections etc…

basically you know touchpoint1 and you know touchpoint2(which is off screen), you just need to work out where in that equation does the boundary box gets intersected…

I tried doing something with line intersections, when I wanted to do something similar to cutting the rope game… I had a string that was drawn using the newline method, but the new line method doesn’t have a touch event… so I had to use line intersections to work out if the rope was getting intersected… sorry rambled on there…

Vik [import]uid: 67619 topic_id: 20449 reply_id: 80103[/import]

Then how would you detect when your finger has gone off of the screen on a real device? [import]uid: 48545 topic_id: 20449 reply_id: 81081[/import]

display.ContentHeight and display.ContentWidth would give you the dimensions of the current device… anything above that would be off screen… [import]uid: 67619 topic_id: 20449 reply_id: 81125[/import]

I haven’t tested this yet on physical hardware… but on a real device, wouldn’t your touch event end as soon as your finger leaves the screen area?

Since the phone can’t detect your touch anywhere that’s not on the screen, how would it know the difference between dragging your finger off the edge, and just lifting your finger up? [import]uid: 115687 topic_id: 20449 reply_id: 81129[/import]

Oh, just saw your second post vik_b_it… that makes sense. Thanks for your replies! [import]uid: 115687 topic_id: 20449 reply_id: 81131[/import]

@vik_b_it: How could a touch event be created when your finger is off the screen?
@losurem: Whether or not the touch event ends when your finger slides off the device is a key question. I am not able to test this. Anyone? [import]uid: 48545 topic_id: 20449 reply_id: 81151[/import]

a touch event cannot be “created” if your finger is off the screen

But you might have a situation where you touch the screen and move your finger off the screen (phase = move or ended)

does that answer your question?

if the touch event ends when your finger slides off the device, you have what you need with the “ended” phase
if it doesn’t… then use the “moved” phase and check the event.x and event.y with the content.displayWidth and content.displayHeight

With my current android device it seems to fire off the ended phase as soon as you are off the screen… [import]uid: 67619 topic_id: 20449 reply_id: 81242[/import]

@vik_b_it:

If an “end” event is created when no finger is on the screen anymore then problem solved. I have just not been able to test for that or found such description in the documentation.

Thanks vik_b_it :slight_smile: [import]uid: 48545 topic_id: 20449 reply_id: 81255[/import]