Clarification about multitouch and setFocus function: is it a one-to-many relationship?

Hello, could you please clarify a few things about multitouch and the setFocus function please?

  1. When using multitouch, is the relationship only 1 to 1, or is it 1 to many? In other words, if I do: 

    StageObject:setFocus(obj1, id1) StageObject:setFocus(obj1, id2)

My intention would be to assign the foci of both touch1 and touch 2 to obj1, not to override the first focus with the second focus.

Thank you!

Hi @jhow,

I don’t think it works like you want it to (but I may be wrong, as multitouch can be tricky). According to the :setFocus docs:

When calling this method while multitouch is enabled, the optional parameter touchID means that the specified touch has focus on that object, but other touches do not. Using this API, it is possible to create an object that will “own” the first touch it gets, for the lifetime of that touch, and for multiple objects to obtain their own focused touches at the same time.

So basically, the object will get the first touch – and that touch will focus on it – but then the second touch will be ignored on that object because you have it associated with (and only with) the first touch.

Instead of using :setFocus(), I think you could accomplish this with some of your own logic and touch handling. For example, keep a table on each object as a property of that object, and when the object is touched, add that event.id to the table. When another touch (second finger) occurs on that object, add it to the table as well. At that point, you know that the object has those two touches associated with it. If a third touch occurs on the object, simply ignore it. In addition, when one of those touches ends on the object, remove it from the table so that a different touch can be logged upon it.

Or something like that… again, this can be a tricky ordeal, but most things are possible with a little effort and logic. :slight_smile:

Hope this helps,

Brent

@jhow, if you don’t want to implement this yourself, you can try out my library which solves this issue.

https://github.com/dmccuskey/dmc-touchmanager

cheers, dmc

Hi @jhow,

I don’t think it works like you want it to (but I may be wrong, as multitouch can be tricky). According to the :setFocus docs:

When calling this method while multitouch is enabled, the optional parameter touchID means that the specified touch has focus on that object, but other touches do not. Using this API, it is possible to create an object that will “own” the first touch it gets, for the lifetime of that touch, and for multiple objects to obtain their own focused touches at the same time.

So basically, the object will get the first touch – and that touch will focus on it – but then the second touch will be ignored on that object because you have it associated with (and only with) the first touch.

Instead of using :setFocus(), I think you could accomplish this with some of your own logic and touch handling. For example, keep a table on each object as a property of that object, and when the object is touched, add that event.id to the table. When another touch (second finger) occurs on that object, add it to the table as well. At that point, you know that the object has those two touches associated with it. If a third touch occurs on the object, simply ignore it. In addition, when one of those touches ends on the object, remove it from the table so that a different touch can be logged upon it.

Or something like that… again, this can be a tricky ordeal, but most things are possible with a little effort and logic. :slight_smile:

Hope this helps,

Brent

@jhow, if you don’t want to implement this yourself, you can try out my library which solves this issue.

https://github.com/dmccuskey/dmc-touchmanager

cheers, dmc