forked from kindrowboat/h5ge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvJoy.js
43 lines (36 loc) · 1.11 KB
/
vJoy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//virtual Joystick
function Joy(doc) {
//doc is the document of the parent page
this.x = 0;
this.y = 0
this.dx = 0;
this.dy = 0;
this.startX = 0;
this.startY = 0;
this.touches = [];
this.init = function(){
document = this.doc;
touchable = 'createTouch' in document;
if (touchable){
document.addEventListener('touchstart', this.onTouchStart, false);
document.addEventListener('touchmove', this.onTouchMove, false);
document.addEventListener('touchend', this.onTouchEnd, false);
} // end if
} // end init
this.onTouchStart = function(event){
this.touches = event.touches;
this.startX = this.touches[0].screenX;
this.startY = this.touches[0].screenY;
} // end onTouchStart
this.onTouchMove = function(event){
event.preventDefault();
this.touches = event.touches;
this.dx = this.touches[0].screenX - this.startX;
this.dy = this.touches[0].screenY - this.startY;
} // end onTouchMove
this.onTouchEnd = function(event){
this.touches = event.touches;
this.dx = 0;
this.dy = 0;
} // end onTouchEnd
} // end class def