Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Multitouch gestures

gebgeb
edited May 2012 in General Posts: 5

As far as I understand codea engine does not support multitouch gestures.
Are there any difficulties?

Tagged:

Comments

  • Posts: 196

    Hello @get,

    Not sure what you mean, but Codea handles multitouch just fine.

    You do however need to code your own gestures (pinch to zoom, two finger drag, etc...)

    Cheers,

  • gebgeb
    Posts: 5

    Hello Xavier,
    Nice to hear, could you paste some small example how to detect two and more touches.

  • Posts: 50

    @geb in the examples shipped with codea there is a multi touch example. The icon of that project shows five colored dots.

  • edited May 2012 Posts: 154

    Code! (!!!NOT MADE BY ME!!!)


    -- Use this function to perform your initial setup function setup()     print("This example tracks multiple touches and colors them based on their ID")     -- keep track of our touches in this table     touches = {} end function touched(touch)     if touch.state == ENDED then         touches[touch.id] = nil     else         touches[touch.id] = touch     end end -- This function gets called once every frame function draw()     background(0, 0, 0, 255)          for k,touch in pairs(touches) do         -- Use the touch id as the random seed         math.randomseed(touch.id)         -- This ensures the same fill color is used for the same id         fill(math.random(255),math.random(255),math.random(255))         -- Draw ellipse at touch position         ellipse(touch.x, touch.y, 100, 100)     end end

    :-D :-D

  • gebgeb
    Posts: 5

    Thanks a lot.
    While I examined help I didn't notice this example at first glance.

    Now I'm experimenting with this example and 've found strange behavior: if four fingers are placed over the screen and moved simultaneously up (we get the task bar) and after that all what we drew never disappear until exit.

  • Posts: 1,255

    That's a gesture baked into the OS. It happens in any app (try it now)

    You can turn it off by switching off Multitasking Gestures in the general section of settings.

  • Posts: 179

    The problem is that opening the task tray breaks stuff in Codea, most noticeably physics. Here is an experiments I tried:

    1. Run the Physics lab example.
    2. Use two or three fingers to pick up some blocks.
    3. While holding the blocks, use a fourth finger and drag all fingers up to open the tray.
    4. Drag down to close the tray.
    5. Notice that the gravity is now broken and the objects are stuck in mid air.
    6. Hit the "reset" button and notice the 100 errors generated.

    Does anyone have any ideas on detecting that physics has become broken, and then fixing it in runtime? I am going to experiment a litle bit, maybe pausing and resuming physics would help.

  • Posts: 179

    Actually, I guess gravity does continue working, but anchor points fail to get deleted which is causing the floating block effect. That can be fixed by periodically checking if a touch is currently happening and deleting all anchor points if not. It would be nice to have some way to detect if an OS menu is opened like this.

  • Posts: 384

    Hi @Vega, I've also noticed this effect in non-physics multi touch... When the screen gets hammered with lotsa touches, some stick. I also turned off the iOS gestures a while ago.

  • gebgeb
    Posts: 5

    Small question out of topic: how can I use "if" to check the variable for not equalling any value? I tried if a<>b, if a != b. these don't work.

  • Posts: 2,161

    I think that what happens here is that Codea gets (some of) the touch starting (and movement) events but because the gesture gets eaten by iOS, Codea never gets sent the ENDED events. So if your code does something like "when touch starts, initialise something; while touch is active, do something; when touch ends, destroy something" then the "destroy" never gets called and stuff piles up.

    Exactly how to detect this depends on what you want to do. You could expire all touches that haven't done anything in the last second, you could provide a "blank all active touches" routine that the user can call, you could keep track of the number of active touches and delete them if they go over a certain value.

  • Posts: 2,161

    (geb: if a ~= b then do something end that's a tilde in case it's too hard to see)

Sign In or Register to comment.