Disable multitouch?

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

Thank in advance
Marco

Hi Marco, I have been asking the same question for months. ANSCA, Carlos anyone can you add this feature, please?

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

@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.

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.

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!

Can you post some code?

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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

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.

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

Thanks a lot!

views:1993 update:2011/10/4 8:06:35
corona forums © 2003-2011