Game Development Community

OniPhoneTouch commands not working

by Eyal Erez · in iTorque 2D · 01/12/2009 (9:34 am) · 10 replies

It seems like the oniPhoneTouch commands are not working on 1.1
I believe Conor had the same problem too so it's not just me.
In addition to that, I've enabled useMouseEvent on my guiButtons and although onMouseEnter() works, onMouseDown() doesn't work. this however also doesn't work on 1.7.4 PC so maybe it's just not implemented (although based on the docs it should work)

#1
01/12/2009 (9:41 am)
Can't say anything about the oniPhoneTouch commands, but i'm using onMouseDown on 1.1 and it's working for me.
#2
01/12/2009 (9:54 am)
Yes, onMouseDown works for me too but only on the scenegraph. not on guiButtonCtrl.
The reason I need it to work on guiButtonCtrl is to fix the clunky iPhone guiButtons.
Basically, the guiButtons execute their command onMouseUp which works great using the mouse. but very clunky touching the iPhone.
I'd like execute the button command onMouseDown instead of mouseUp.
#3
01/12/2009 (8:51 pm)
Yes, I'm finding this too. It's pretty serious as it breaks multi-touch functionality.
#4
01/12/2009 (9:07 pm)
I had a look at the code for handling the callbacks, it looks pretty crude. I have updated it for my game and will test it some more before posting here.

By the way, how do you guys expect multi-touch to work? I had a bit of difficulty really understanding what a multitouch event was initially, but it would be interesting to hear your thoughts.
#5
01/12/2009 (9:14 pm)
Disclaimer: I am not an iTGB dev, so use this code at your own peril!

Inside iPhoneInput.mm, replace the function "processMultipleTouches" with this code:

int processMultipleTouches()
{
    /*
        What we want to do here is gather all the touch events and strip their important values, sending them to the script function.
        the script should look something like this:
            function oniPhoneTouchDown( %touchCount, %touchList )
            {
                for ( %i = 0; %i < %touchCount; %i++ )
                {
                    %touchPoint = getWords( %touchList, 2 * %i, 2 * %i + 1 );
                    echo( "Touch #" @ %i @ "x:" SPC getWord( %touchPoint, 0 ) SPC "y:" SPC getWord( %touchPoint, 1 ) );
                }
            }
    */
    
    const int numTouchDownEvents = processTouchEvent(&TouchDownEvents, "oniPhoneTouchDown");
    const int numTouchMoveEvents = processTouchEvent(&TouchMoveEvents, "oniPhoneTouchMove");
    const int numTouchUpEvents   = processTouchEvent(&TouchUpEvents,   "oniPhoneTouchUp");
    
    return numTouchDownEvents + numTouchMoveEvents + numTouchUpEvents;
}

int processTouchEvent(TouchEventVector *eventList, const char *callback)
{
    // Max buffer
    const U32 maxBufferSize = 1024;
    
    // Create Returnable Buffer.
    char* touchBuffer = Con::getReturnBuffer(maxBufferSize);
    
    // Set Buffer Counter.
    U32 bufferCount = 0;
    
    // Buffer all of the event coordinates into a single string
    for (TouchEventVector::iterator i = eventList->begin(); i != eventList->end(); i++)
    {
        if(bufferCount == 0)
        {
            bufferCount += dSprintf(touchBuffer + bufferCount, maxBufferSize - bufferCount, "%d %d", i->x, i->y);
        }
        else
        {
            bufferCount += dSprintf(touchBuffer + bufferCount, maxBufferSize - bufferCount, " %d %d ", i->x, i->y);
        }
    }
    
    const int eventCount = eventList->size();
    if (eventCount > 0 && callback)
    {
        // To string
        char touchCount[8];
        dSprintf(touchCount, sizeof(touchCount), "%d", eventCount);
        
        // Callback
        Con::executef(3, callback, touchCount, touchBuffer);
        
        // Clear the vector
        eventList->clear();
    }
    
    return eventCount;
}

Also, you will need to declare the new function up the top:

int processTouchEvent(TouchEventVector *eventList, const char *callback);

Edit: I forgot to add that instead of parsing separate X and Y values through the callback, it now uses one list of X and Y values (just like any other list of points used in other TGB callbacks). For example: %touchList = "X1 Y1 X2 Y2", instead of %x = "X1 X2", %y = "Y1 Y2".
#6
01/13/2009 (2:40 am)
Thanks for that Phillip. I should add that multitouch with onIphoneTouch was working fine in the previous version.
#7
01/13/2009 (2:54 am)
I prefer the method posted above. It follows the same kind of methodology used for other lists of coordinates (poly points, contact points on collisions, etc).
#8
02/14/2009 (10:57 pm)
Phillip - when I add this code to iPhoneInput.mm I get a build error on the function declaration saying TouchEventVector not declared in this scope. Any tips? Sorry, I'm an XCode n00b.
#9
02/15/2009 (1:58 am)
Note - to get multi-touch working again in iTGB 1.1 set this:

$pref::iPhone::enableMultipleTouch = true

in your defaultPrefs.cs
#10
02/15/2009 (12:07 pm)
Sorry Conor, it is a typedef of a Vector of touchEvents:

typedef Vector<touchEvent> TouchEventVector;
TouchEventVector TouchMoveEvents;//<Mat> to make sure we don't have multiple events per frame
TouchEventVector TouchDownEvents;
TouchEventVector TouchUpEvents;