Multitouch ENDED sticky

Hi there, in the example ‘Multitouch’, when i use more than three fingers, some of the ellipses do not stop because they don’t get a ENDED state, in my own program, i have the same issue. How can i fix this? Thanks in advance!

I noticed this feature on some of my projects…

To avoid or at least reduce it I added a check on CurrentTouch, basically if there is no current touch then you clean up your multitouch table because no touches are occuring, so a stuck multitouch will only keep running while at least one other touch is occuring.

Below is my general mutlitouch pattern

function touched(touch)
    if touch.state == ENDED then
        touches[touch.id] = nil
    else
        touches[touch.id] = touch
    end    
end    

function touchActions()
    for k,v in pairs(touches) do 
        if CurrentTouch.state == ENDED then
            --if there are no current touches then we kill all current touches to avoid bugged ball producers
            touches[k] = nil
        else
                
            --do your touch related actions
            
        end    
    end
end

function draw()
    touchActions()
end

Thank you! Just what i needed!

But this kills all of the touches in the table when NO touches are detected at all, but is there any way to do this only for the ones that are not touched? Because on my project, there Re always more that 6 fingers on the tablet, which almost never causes all of the touches to be ENDED…

The issue is the touched function is only called when the touch either begins, ends or is moving. And sometimes misses the ends…

Below is a tweaked version of my previous method, rather than waiting for all touches to end it says if a touch doesn’t move for 1 second, then it ends also. You could set that longer by adjusting the number on ElapsedTime - 1 to more seconds.

function setup()
    touches = {}
end
    
function touched(touch)
    if touch.state == ENDED then
        touches[touch.id] = nil
    else
        --if touches[touch.id] == nil then
        touches[touch.id] = {touch = touch, lastTouch = ElapsedTime }
        --end
    end    
end    

function touchActions()
    for k,v in pairs(touches) do 
        if CurrentTouch.state == ENDED or touches[k].lastTouch < ElapsedTime - 1 then
            --if there are no current touches or the touch is unmoving then we kill all current touches to avoid bugs
            touches[k] = nil
        else
            --do touch actions here
        end    
    end
end

function draw()
    touchActions()
    background(0,0,0,0)
    for k,v in pairs(touches) do
        ellipse(v.touch.x, v.touch.y, 100)
    end
end

Mmmh, this works but the controls dont work smoothly, because if you keep touched pressed, it will go nil every second, if you know what i mean. How can i change it so it only counts the elapsedTime if you are no longer pressing it… Or something like that? Thanks.

It only goes nil if your finger remains completely still. If you set it to a few seconds the likelihood that in normal use your finger was absolutely still for 5 seconds would be very low. I don’t know of any way to fix it other than this.