Game Development Reference
In-Depth Information
While Marmalade does provide a polling-based approach to handling multi-touch
events, the callback approach is possibly the better choice as it leads to slightly more
elegant code and is a little more efficient.
Detecting multi-touch input using polling
Marmalade provides us with a set of functions to allow multi-touch
detection. The functions s3ePointerGetTouchState , s3ePointerGetTouchX(i); ,
and s3ePointerGetTouchY(i); are equivalent to the single touch functions
s3ePointerGetState , s3ePointerGetX , and s3ePointerGetY , except that
the multi-touch versions take a single parameter—the touch ID number.
The s3ePointer API also declares a preprocessor define S3E_POINTER_TOUCH_MAX
that indicates the maximum possible value for the touch ID number (plus one!).
As the user touches and releases the display, the touch ID numbers will be re-used.
It is important to bear this in mind.
The following code snippet shows a loop that will allow us to process the currently
active touch points:
for (uint32 i = 0; i < S3E_POINTER_TOUCH_MAX; i++)
{
// Find position of this touch id. Position is only valid if the
// state for the touch ID is not S3E_POINTER_STATE_UNKNOWN or
// S3E_POINTER_STATE_UP
int32 x = s3ePointerGetTouchX(i);
int32 y = s3ePointerGetTouchY(i);
switch(s3ePointerGetTouchState(i))
{
case S3E_POINTER_STATE_RELEASED:
// User just released the screen at x,y
break;
case S3E_POINTER_STATE_DOWN:
// User just pressed or moved their finger to x,y
// We need to know if we've already been tracking this
// touch ID to tell whether this is a new press or a move
break;
default:
// This touch ID is not currently active
break;
}
}
 
Search WWH ::




Custom Search