Disable multitouch?

Hi guyz,
is possible disable multitouch enabled with system.activate(“multitouch”)

Thank in advance
Marco

[import]uid: 7518 topic_id: 3474 reply_id: 303474[/import]

Hi Marco, I have been asking the same question for months. ANSCA, Carlos anyone can you add this feature, please?
[import]uid: 8192 topic_id: 3474 reply_id: 16764[/import]

The touch events need only to have the event id ignored in your code to behave just as if multitouch is disabled.

http://developer.anscamobile.com/content/events-and-listeners#Changes_in_multitouch_for_Beta_6

m [import]uid: 8271 topic_id: 3474 reply_id: 16793[/import]

@horacebury. Thanks for the pointer. I looked at the documentation and the sample code but I have a hard time understanding what the id is.

Is it 1,2,3,4 etc? It’s not really clear. [import]uid: 8192 topic_id: 3474 reply_id: 16803[/import]

Well, generally you don’t need to make use of the id, just pass it on to the setFocus function, if that’s what you want to do. Essentially, if you don’t want to use multitouch, just don’t make use of the id and simply make sure that when you receive a “began” touch event you set your flag or whatever to know that the touch has begun. Any other touches will be ignored by your code because you’re already dealing with that touch.

If you wanted to handle multiple touches at once, you’d have to write code to carry the touch event id along with the object being moved for the duration of the touch. Simply not doing that pretty much enforces a single touch environment.

As I understand it, if you don’t enable multitouch but actually put two fingers on the screen at the same time, two events are generated, they are just indistinguishable. ie: The x,y values would appear to jump around. But don’t quote me on that.

Ultimately, what I think you are trying to do is not actually disable multitouch (because you can’t stop the user from putting more than one finger on the screen) but to simply deal with only the first touch on the screen which, realistically, you have to manage anyway - because you can’t stop the user touching the screen twice.

This last point is important, because it is what the setFocus function helps you do - to tell the device that this touch is the one you care about and no other, until you cancel the act by passing nil. Passing an ID with the object to the setFocus function is simply tracking multiple touches, each with their own ID.

I hope this helps. What I should have done is tested single touch events on a device, but I’m a bit lazy right now.

Matt. [import]uid: 8271 topic_id: 3474 reply_id: 16811[/import]

Hi, Matt!

I am looking for a solution to “deactivate” the multitouch feature, and i was reading your posts.
You say: “…simply make sure that when you receive a “began” touch event you set your flag or whatever to know that the touch has begun. Any other touches will be ignored by your code because you’re already dealing with that touch.”
This is what I need, but if I touch on another part of my device when I’m touching the object i’m working with, the app crash.
I use setFocus, as you told, but I can’t fix this yet.

As you told, ehat i want is to “…simply deal with only the first touch on the screen which, realistically, you have to manage anyway”

Could you tell me what am i doing wrong?

Thanks in advance! [import]uid: 44013 topic_id: 3474 reply_id: 55712[/import]

Can you post some code? [import]uid: 8271 topic_id: 3474 reply_id: 55715[/import]

Hi, Matt!

Thanks for reply soon!

In fact, I am playing with the scrollnav.lua from John Polacek, do you know it? (http://developer.anscamobile.com/code/video-gallery)

There’s a function on him code:

function scrollNav:touch(event)   
  
 local phase = event.phase   
  
 if(phase == "began") then  
  
 self.startPos = event.x  
 self.prevPos = event.x   
 self.delta, self.velocity = 0, 0  
 if self.tween then transition.cancel(self.tween) end  
  
 Runtime:removeEventListener("enterFrame", scrollNav)   
  
 self.prevTime = 0  
 self.prevX = 0   
  
 -- Start tracking velocity  
 Runtime:addEventListener("enterFrame", trackVelocity)  
  
 -- Subsequent touch events will target button even if they are outside the contentBounds of button  
 display.getCurrentStage():setFocus(self)  
 self.isFocus = true  
  
 elseif(self.isFocus) then  
  
 if(phase == "moved") then   
 local rightLimit = screenW - self.width - self.right  
  
 self.moved = true  
 self.delta = event.x - self.prevPos  
 self.prevPos = event.x  
 if (self.x \> self.left or self.x \< rightLimit) then   
 self.x = self.x + self.delta/2  
 else  
 self.x = self.x + self.delta   
 end  
  
 elseif(phase == "ended" or phase == "cancelled") then   
 local dragDistance = event.x - self.startPos  
 self.lastTime = event.time  
  
 Runtime:addEventListener("enterFrame", scrollNav)   
 Runtime:removeEventListener("enterFrame", trackVelocity)  
  
 -- Allow touch events to be sent normally to the objects they "hit"  
 display.getCurrentStage():setFocus(nil)  
 self.isFocus = false  
 --print("X: "..event.x)  
 --print("Y: "..event.y)  
 --print("tM: "..scrollNav.topMargin)  
 --print("bM: "..scrollNav.bottomMargin)  
 -- check if touch instance is a drag or a touch to open content  
 if (dragDistance \< 10 and dragDistance \> -10 and event.y \> topMargin and event.y \< bottomMargin) then  
 elementoSlider=getContent(event.x)  
 local event = { name="scrollNav.elemElexido", target=elementoSlider }  
 --print("Despacha!")  
 --Runtime:dispatchEvent(event)  
 scrollNav:dispatchEvent(event)  
 end  
 end  
 end  
  
 return true  
 end  

I suppose I must change something at this function to deal with only the first touch on the screen.
What do you think about? [import]uid: 44013 topic_id: 3474 reply_id: 55732[/import]

Really, I would have a global flag which gets set to true in the began event. Whenever that variable is true simply don’t handle any events other than the one which set it. When that event (found via it’s corresponding ID) ends, unset the flag. This is the core of how you would stop any more than the first touch event from being able to do anything, though you may have to modify a lot of code to know about it. [import]uid: 8271 topic_id: 3474 reply_id: 55743[/import]

Ok Matt, I think I understand you… I’ll try to go on this way. Hope I can solve it.

Thanks a lot! [import]uid: 44013 topic_id: 3474 reply_id: 55746[/import]

There is an API to disable multitouch: system.deactivate( “multitouch” ). For some reason it was never documented, but it is now. http://developer.anscamobile.com/reference/index/systemdeactivate [import]uid: 7559 topic_id: 3474 reply_id: 91634[/import]

Good!
Thanks Tom.
Marco
[import]uid: 7518 topic_id: 3474 reply_id: 92153[/import]