Game Development Reference
In-Depth Information
Working with Touch
In Windows 8 apps, we have very granular control over detecting the type of touch input our
app is receiving. When it comes to WebKit games, there is a clear distinction between touch
and mouse clicks. Usually in a WebKit app, you would do something like this:
var touchEnabled = 'createTouch' in document
From there, you could split up the logic in your app to handle touch differently than mouse
controls.
if (touchEnabled) {
//Touch is enabled
canvas.addEventListener( 'touchmove', onTouchMove, false );
} else {
// Use mouse events instead
canvas.addEventListener( 'mousemove', onMouseMove, false );
}
Instead, on Windows 8, you can simply handle all mouse and touch events the same since
you have access to an input abstraction class called the MSPointer. On Window 8, we refer to
this as “handling touch-first input without compromising mouse,” and there is a great article
on it here . It's important to note that you can also check if the device is touch enabled, just
like you do on WebKit, like so:
var touchEnabled = window.navigator.msPointerEnabled
To help illustrate how touch and mouse input is handled on Windows 8, take a look at Fig-
ure 4-1 .
Search WWH ::




Custom Search