-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjoyTest.html
80 lines (68 loc) · 1.82 KB
/
joyTest.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Virtual Joystick test</title>
<script type="text/javascript">
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.x = this.touches[0].screenX;
this.y = this.touches[0].screenY;
this.startX = this.x;
this.startY = this.y;
} // end onTouchStart
this.onTouchMove = function(event){
event.preventDefault();
this.touches = event.touches;
this.x = this.touches[0].screenX;
this.y = this.touches[0].screenY;
this.dx = this.x - this.startX;
this.dy = this.y - this.startY;
} // end onTouchMove
this.onTouchEnd = function(event){
this.touches = event.touches;
this.dx = 0;
this.dy = 0;
} // end onTouchEnd
this.init();
} // end class def
var output;
var counter = 0;
var joy;
function init(){
output = document.getElementById("output");
joy = new Joy(document);
setInterval(update, 20);
} // end init
function update(){
counter++;
//joy.update();
output.innerHTML = counter + "<br />";
output.innerHTML += "x: " + joy.x + ", y: " + joy.y + "<br />";
}
</script>
</head>
<body onload = "init()">
<div id = "output">
default
</div>
</body>
</html>