Created
October 12, 2013 10:18
-
-
Save anonymous/6948331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pc.script.create('mobile_touch', function (context) { | |
var canvas, ctx, touch = {current:{},last:{}}; | |
// Creates a new Mobile_touch instance | |
var Mobile_touch = function (entity) { | |
this.entity = entity; | |
}; | |
Mobile_touch.prototype = { | |
initialize: function () { | |
this.pointer = context.root.findByName("pointer"); | |
canvas = document.getElementById('application-canvas'); | |
canvas.addEventListener("touchstart", this.onTouchStart, false); | |
canvas.addEventListener("touchend", this.onTouchEnd, false); | |
}, | |
update: function (dt) { | |
}, | |
onTouchStart: function(e){ | |
touch.last.x = e.touches[0].clientX; | |
touch.last.y = e.touches[0].clientY; | |
}, | |
onTouchEnd: function(e){ | |
touch.current.x = touch.last.x - e.changedTouches[0].clientX; | |
touch.current.y = touch.last.y - e.changedTouches[0].clientY; | |
var pointerRot = pc.math.vec3.create(0,0,0); | |
if(Math.abs(touch.current.x) > Math.abs(touch.current.y)) | |
{ | |
if(touch.current.x > 5 || touch.current.x < -5) | |
{ | |
if(touch.current.x > 0) pointerRot[2] = 90; | |
else pointerRot[2] = -90; | |
} | |
} | |
else | |
{ | |
if(touch.current.y > 5 || touch.current.y < -5) | |
{ | |
if(touch.current.y < 0) pointerRot[2] = 180; | |
} | |
} | |
context.root.findByName("pointer").setEulerAngles(pointerRot); | |
}, | |
}; | |
return Mobile_touch; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment