Game Development Reference
In-Depth Information
The biggest issue with this approach is that Marmalade never sends us an explicit
notification that a touch event has just occurred. The s3ePointerGetTouchState
function never returns S3E_POINTER_STATE_PRESSED , so instead we need to keep
track of all touch IDs we have seen active so far when handling S3E_POINTER_
STATE_DOWN . If a new touch ID is seen, we have detected the just-pressed condition.
While this code will work, I hope you will find that the callback-based approach that
we are about to consider leads to a slightly more elegant solution.
Multi-touch input using callbacks
As with the polling approach, multi-touch detection using callbacks is almost exactly
the same as the single touch callback method. We still use s3ePointerRegister and
s3ePointerUnRegister to start and stop events being sent to our code, but instead
we use S3E_POINTER_TOUCH_EVENT to receive notifications of the user pressing or
releasing the screen, and S3E_POINTER_TOUCH_MOTION_EVENT to find out when the
user has dragged their finger across the screen.
The callback function registered to S3E_POINTER_TOUCH_EVENT will be sent a
pointer to an s3ePointerTouchEvent structure. This structure contains the screen
coordinates where the event occurred (the m_x and m_y members), whether the
screen was touched or released (the m_Pressed member, which will be set to 1 if the
screen was touched), and most importantly the ID number for this touch event (the
m_TouchID member), which we can use to keep track of this touch as the user moves
their finger around the display.
The S3E_POINTER_TOUCH_MOTION_EVENT callback will receive a pointer to an
s3ePointerTouchMotionEvent structure. This structure contains the ID number
of the touch event that has been updated and the new screen coordinate values.
These structure members have the same names as their equivalent members in the
s3ePointerTouchEvent structure.
Marmalade provides us with no way of adjusting the frequency of touch events.
Instead, it is really just dependant on how often the underlying operating system
code dispatches such events.
Hopefully you can see that the callback-based method is a little neater than the
polled method. Firstly, we can say goodbye to the truly nasty loop needed in the
polled method to detect all currently active touches.
Secondly, with careful coding we can use the same code path to handle both single
and multi-touch input. If we code first for multi-touch input, then making single
touch work is simply a case of adding a fake touch ID to incoming single touch
events and passing them through to the multi-touch code.
 
Search WWH ::




Custom Search