Posted: 22nd Oct 2011 11:50
How do I detect and handle multitouch? Is it even possible?

Say, I want a game where the device is laying on a table, and two players are sitting on the opposite sides of the device screen, each controlling a pad. How can player 1 move his pad on the screen, even if player 2 is pressing on his side of the screen?

As it is now, only one touch event can be tracked...
Posted: 22nd Oct 2011 12:13
When I used an HP TouchSmart multitouch machine, AppGameKit reported that multitouch was not supported, when it was. Perhaps it's the same issue?
Posted: 22nd Oct 2011 12:18
You might need to use platform specific commands like GetRawTouchCount().
Posted: 23rd Oct 2011 4:37
The Windows platform does not currently support touch screens, hopefully we can get that into a future update.

Here's some code that demonstrates how you can use the multitouch commands

+ Code Snippet
rem create 3 sprites to represent touch points
CreateSprite( 1, 0 )
SetSpriteColor( 1, 255,0,0,255 )

CreateSprite( 2, 0 )
SetSpriteColor( 2, 0,255,0,255 )

CreateSprite( 3, 0 )
SetSpriteColor( 3, 0,0,255,255 )

dim assigned[3] as integer

do
    assigned[1] = 0
    assigned[2] = 0
    assigned[3] = 0

    rem find out which sprites are currently assigned to points
    touchID = GetRawFirstTouchEvent(1)
    while touchID > 0
        sprite = GetRawTouchValue( touchID )
        if ( sprite > 0 ) then assigned[sprite] = 1
        touchID = GetRawNextTouchEvent()
    endwhile

    rem move assigned sprites to touch locations
    touchID = GetRawFirstTouchEvent(1)
    while touchID > 0
        x# = GetRawTouchCurrentX( touchID )
        y# = GetRawTouchCurrentY( touchID )
        sprite = GetRawTouchValue( touchID )

        if ( sprite = 0 )
            rem assign this new touch point a sprite
            if ( assigned[1] = 0 )
                sprite = 1
            elseif ( assigned[2] = 0 )
                sprite = 2
            elseif ( assigned[3] = 0 )
                sprite = 3
            endif

            SetRawTouchValue( touchID, sprite )
        endif

        if ( sprite > 0 )
            SetSpritePosition( sprite, x#, y# )
        endif

        touchID = GetRawNextTouchEvent()
    endwhile

    Sync()
loop
Posted: 23rd Oct 2011 5:53
Thanks Paul, I am uploading a video of this working onto You Tube so check that out in a few hours. You'll find it hosted on our TGC you tube page but I will also tweet it when it's finished uploading. As I stress in the video, multi touch is a very cool thing but be warned that any app that uses the raw commands throws away the guarantee that your app can run fully on EVERY device. Many devices including most desktops cannot perform any kind of multi-touch operation so your app may not work fully on those systems. If you DO want to use multi-touch, I suggest adding it as an extra mode of play. There is a command in AppGameKit which can detect for the presence of multi-touch. Have fun!
Posted: 23rd Oct 2011 15:10
Brilliant Paul! I'll play more with your code later, when I'm done with my WIP