forked from bobboteck/JoyStick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joy.html
173 lines (162 loc) · 6.54 KB
/
joy.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE HTML>
<!--
The MIT License (MIT)
This file is part of the JoyStick Project (https://github.com/bobboteck/JoyStick).
Copyright (c) 2015 Roberto D'Amico (Bobboteck).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<html>
<head>
<title>Joy</title>
<meta charset="utf-8">
<meta name="description" content="Example page of use pure Javascript JoyStick">
<meta name="author" content="Roberto D'Amico">
<link rel="shortcut icon" type="image/png" href="http://bobboteck.github.io/img/roberto-damico-bobboteck.png">
<style>
*
{
box-sizing: border-box;
}
body
{
margin: 0px;
padding: 0px;
font-family: monospace;
}
.row
{
display: inline-flex;
clear: both;
}
.columnLateral
{
float: left;
width: 15%;
min-width: 300px;
}
.columnCetral
{
float: left;
width: 70%;
min-width: 300px;
}
#joy2Div
{
width:200px;
height:200px;
margin:50px
}
#joystick
{
border: 1px solid #FF0000;
}
#joystick2
{
border: 1px solid #0000FF;
}
</style>
<script src="joy.js"></script>
</head>
<body>
<!-- Example of FIXED or ABSOLUTE position -->
<div id="joy3Div" style="width:200px;height:200px;margin:50px;position:fixed;bottom:30px;left:500px;"></div>
<div style="position:fixed;bottom:125px;left:750px;">
Posizione X:<input id="joy3PosizioneX" type="text" /><br />
Posizione Y:<input id="joy3PosizioneY" type="text" /><br />
Direzione:<input id="joy3Direzione" type="text" /><br />
X :<input id="joy3X" type="text" /></br>
Y :<input id="joy3Y" type="text" />
</div>
<!-- Example of two JoyStick integrated in the page structure -->
<div class="row">
<div class="columnLateral">
<div id="joy1Div" style="width:200px;height:200px;margin:50px"></div>
Posizione X:<input id="joy1PosizioneX" type="text" /><br />
Posizione Y:<input id="joy1PosizioneY" type="text" /><br />
Direzione:<input id="joy1Direzione" type="text" /><br />
X :<input id="joy1X" type="text" /></br>
Y :<input id="joy1Y" type="text" />
</div>
<div class="columnCetral">
<h2>JoyStick</h2>
<p>
A simple JoyStick that use HTML5, Canvas and JavaScript, for touch and mouse interfaces (no JQuery required).<br /><br />
The project is available at <a href="https://github.com/bobboteck/JoyStick">https://github.com/bobboteck/JoyStick</a>.<br /><br />
The left JoyStick (in red square) is an example that use default parametrs, the right JoyStick (in blue square) instead use same custom parameters, specifically the title and the autoReturnToCenter disabled, this also uses CSS class instead inline style.<br /><br />
<b>NOTE:</b> currently the JoyStick does not work correctly if inserted in a Table tag, to put more than one JoyStick on a single line it is recommended to create a structure with the Div, as in this example page.
</p>
</div>
<div class="columnLateral">
<div id="joy2Div"></div>
Posizione X:<input id="joy2PosizioneX" type="text" /></br>
Posizione Y:<input id="joy2PosizioneY" type="text" /></br>
Direzione:<input id="joy2Direzione" type="text" /></br>
X :<input id="joy2X" type="text" /></br>
Y :<input id="joy2Y" type="text" />
</div>
</div>
<script type="text/javascript">
// Create JoyStick object into the DIV 'joy1Div'
//var Joy1 = new JoyStick('joy1Div');
var joy1IinputPosX = document.getElementById("joy1PosizioneX");
var joy1InputPosY = document.getElementById("joy1PosizioneY");
var joy1Direzione = document.getElementById("joy1Direzione");
var joy1X = document.getElementById("joy1X");
var joy1Y = document.getElementById("joy1Y");
/*
setInterval(function(){ joy1IinputPosX.value=Joy1.GetPosX(); }, 50);
setInterval(function(){ joy1InputPosY.value=Joy1.GetPosY(); }, 50);
setInterval(function(){ joy1Direzione.value=Joy1.GetDir(); }, 50);
setInterval(function(){ joy1X.value=Joy1.GetX(); }, 50);
setInterval(function(){ joy1Y.value=Joy1.GetY(); }, 50);
*/
// Create JoyStick object into the DIV 'joy1Div'
var Joy1 = new JoyStick('joy1Div', {}, function(stickData) {
joy1IinputPosX.value = stickData.xPosition;
joy1InputPosY.value = stickData.yPosition;
joy1Direzione.value = stickData.cardinalDirection;
joy1X.value = stickData.x;
joy1Y.value = stickData.y;
});
// Create JoyStick object into the DIV 'joy2Div'
var joy2Param = { "title": "joystick2", "autoReturnToCenter": false };
var Joy2 = new JoyStick('joy2Div', joy2Param);
var joy2IinputPosX = document.getElementById("joy2PosizioneX");
var joy2InputPosY = document.getElementById("joy2PosizioneY");
var joy2Direzione = document.getElementById("joy2Direzione");
var joy2X = document.getElementById("joy2X");
var joy2Y = document.getElementById("joy2Y");
setInterval(function(){ joy2IinputPosX.value=Joy2.GetPosX(); }, 50);
setInterval(function(){ joy2InputPosY.value=Joy2.GetPosY(); }, 50);
setInterval(function(){ joy2Direzione.value=Joy2.GetDir(); }, 50);
setInterval(function(){ joy2X.value=Joy2.GetX(); }, 50);
setInterval(function(){ joy2Y.value=Joy2.GetY(); }, 50);
var joy3Param = { "title": "joystick3" };
var Joy3 = new JoyStick('joy3Div', joy3Param);
var joy3IinputPosX = document.getElementById("joy3PosizioneX");
var joy3InputPosY = document.getElementById("joy3PosizioneY");
var joy3Direzione = document.getElementById("joy3Direzione");
var joy3X = document.getElementById("joy3X");
var joy3Y = document.getElementById("joy3Y");
setInterval(function(){ joy3IinputPosX.value=Joy3.GetPosX(); }, 50);
setInterval(function(){ joy3InputPosY.value=Joy3.GetPosY(); }, 50);
setInterval(function(){ joy3Direzione.value=Joy3.GetDir(); }, 50);
setInterval(function(){ joy3X.value=Joy3.GetX(); }, 50);
setInterval(function(){ joy3Y.value=Joy3.GetY(); }, 50);
</script>
</body>
</html>