touch state=3

Did a quick search and there have been previous threads alluding to this, but rather than resurrect one of these (which seems to annoy some people) I thought I’d post an observation I had about the elusive touch.state=CANCELLED (or 3). I came across this by using the triple tap to get the buttons to reappear.

-- touchtrial

-- Use this function to perform your initial setup
function setup()
    touches={}
end

-- This function gets called once every frame
function draw()
    text("Triple tap, then single tap then single tap and so on",WIDTH/2,HEIGHT/2)
end

function touched(touch)
    if touch.state == ENDED then
--    if touch.state == ENDED or touch.state==CANCELLED then
        local cc=0
        for i,k in pairs(touches) do
            print(i.." state "..k.state)
            cc = cc + 1
        end
        print("current stored touches="..cc)

        
        touches[touch.id] = nil

    else
        touches[touch.id] = touch      
    end
end

@Simeon this issue also manifests itself in the multitouch example - triple tap and three circles persist - might be worth tidying this up for the new release of Codea

Related: http://twolivesleft.com/Codea/Talk/discussion/comment/40384#Comment_40384

And there are other posts about this dating back awhile.

IMO it’s a huge bug, and it really makes multitouch mostly pointless :confused:

@toadkick - oops didn’t see that thread otherwise I would have appended to the end of it.

@west do not fear the flamers. It causes people not to post because they are afraid of getting “flamed”.

I tried to reproduce this effect in my spacewar 2 player app. It doesn’t seem to have that bug, or maybe I just don’t understand how to make it happen?

If you have a second take a look and see if you can make it happen. The code is on codea community, or if you just want to run it you download it from the App Store for free.

If it doesn’t have the bug I promise it is pure luck, nothing to do with my coding skills.

@MrScience101 your app explicitly states that the players are to use only one finger each so your encouraging them not to use a triple tap. The issue will still be there, it’s just that you have nothing requiring a triple tap and won’t notice it.

It causes an issue if you have an app where you are trying to track more than two touches at once. Triple tapping with three fingers is a sequence used to get the onscreen buttons to reappear if using FULLSCREEN_NO_BUTTONS - this interrupts the standard touch handling and causes issues.

@toadkick this is going to change as follows

  • Triple tap gesture will be disabled in every mode except FULLSCREEN_NO_BUTTONS
  • Triple tap escape sequence is not enabled for Xcode exported builds (currently the case). So the no buttons displayMode will work fine in published apps.
  • You can test any complex multi-touch specific sequences using FULLSCREEN or other display modes besides the no-buttons one

@west thank you for trying. I figured since there are two players, both using two fingers, that would add up to 2, 3, or 4 taps most of the time. Looks like Simeon mentioned when you export it to xcode that problem goes away because it is disabled.

Thank you @Simeon, this is good news!

Hi,

just to check in a new game I’m developing the player taps the screen anywhere to shoot and people can tap with both hands to increase the amount of bullets (ie alternating).

Something I’ve found is that by doing this fast tapping results in the music fading out and starting over. Is this to do with the multi tap gesture to break out of full screen ?

Thanks

@Majormorgan According to the reference, only 1 music track can play at a time. So if ones playing and you start another, the first one will stop and the second will start.

@dave1707 couldn’t this be solved by converting the music file to wav and using sound()?

@Luatee @Majormorgan That’s more trouble than I would go thru. I believe you can check if the music is playing and if it is, don’t start it again.

EDIT: Use music.duration and music.currentTime .

Hi, thanks for your suggestions. It only happens when I don’t use

Fullscreen no buttons

It’s only some thing triggered by the multi touch thing and just wanted to disable that if possible

Thanks @dave1707 it’s only ever a single track playing and I have code that switches the track depending on the game state. The bug is something the multitouch does to the runtime that means when multi touch triggers this issue the game stops and the music fades out, but then it all carries on.