Multitouch gestures

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

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…)


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

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

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 = {}

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

-- 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
        -- This ensures the same fill color is used for the same id
        -- Draw ellipse at touch position
        ellipse(touch.x, touch.y, 100, 100)

:smiley: :smiley:

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.

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.

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.

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.

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.

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.

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.

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