HTML and CSS Reference
In-Depth Information
/* This code is used to run as soon as appMobi activates */
var onDeviceReady=function(){
// Size the display to 320px by 480px
AppMobi.display.useViewport(320,480)
// hide splash screen
AppMobi.device.hideSplashScreen();
// Load files for Direct Canvas
AppMobi.canvas.load("index.js");
var keys = {}
var trackTouch = function(e) {
var touch, x;
var gutterWidth = 10;
var unitWidth = 320/5;
var blockWidth = unitWidth-gutterWidth;
e.preventDefault();
keys['left'] = false;
keys['right'] = false;
for(var i=0;i<e.touches.length;i++) {
touch = e.touches[i];
x = touch.pageX;
if(x < unitWidth) {
keys['left'] = true;
}
if(x > unitWidth && x < 2*unitWidth) {
keys['right'] = true;
}
}
if(e.type == 'touchstart' || e.type == 'touchend') {
for(i=0;i<e.changedTouches.length;i++) {
touch = e.changedTouches[i];
x = touch.pageX;
if(x > 4 * unitWidth) {
keys['fire'] = (e.type == 'touchstart');
}
}
}
AppMobi.canvas.execute('Game.setKeys('+ keys["left"] + ","
+ keys["right"] + ","
+ keys["fire"] + ")");
};
document.addEventListener('touchstart',trackTouch,false);
document.addEventListener('touchmove',trackTouch,false);
Search WWH ::




Custom Search