-
Notifications
You must be signed in to change notification settings - Fork 69
/
screen-controls-joystick-dual.html
151 lines (122 loc) · 3.46 KB
/
screen-controls-joystick-dual.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
<!DOCTYPE html>
<html>
<head>
<title>Screen Controls</title>
<meta name="description" content="A-Frame Examples">
<script src="js/aframe-master-v1.3.0.min.js"></script>
<script src="js/aframe-environment-component.min.js"></script>
<script src="js/extended-wasd-controls.js"></script>
<script src="js/joystick.js"></script>
<style>
body
{
/* disable long press in iOS? */
-webkit-touch-callout: none;
}
.mainUI
{
border: 0px solid pink;
position: fixed;
top: 0px;
width:99%;
height:99%;
z-index: 1;
pointer-events: none; /* allow click-through in transparent areas */
}
.regionUI
{
border: 0px solid yellow;
position: absolute;
display: flex;
flex-direction: row;
pointer-events: none;
}
.buttonUI
{
border: 0px solid lime;
display: flex;
flex-direction: column;
justify-content: center;
pointer-events: auto;
filter: drop-shadow(0px 0px 20px white);
}
.skyColor
{
filter: hue-rotate(240deg) saturate(100%) brightness(100%) drop-shadow(0px 0px 20px white);
}
.baseColor
{
filter: hue-rotate(24deg) saturate(68%) brightness(100%) drop-shadow(0px 0px 20px white);
}
.grayColor
{
filter: hue-rotate(0deg) saturate(0%) brightness(100%) drop-shadow(0px 0px 20px white);
}
</style>
</head>
<body>
<!-- note: by using red base images for buttons, can tint (HSV) using filter: hue-rotate(); etc. -->
<div class="mainUI" id="uiDiv" oncontextmenu="return false;">
<!-- top-left -->
<div class="regionUI skyColor" style="top: 10px; left: 10px;" oncontextmenu="return false;">
</div>
<!-- top-right -->
<div class="regionUI" style="top: 10px; right: 10px;">
</div>
<!-- bottom-left -->
<div class="regionUI" style="bottom: 10px; left: 10px;">
<div class="buttonUI" style="width: 128px; opacity:0.80;">
<img src="images/joystick-base.png"/>
<div id="stick1" style="position: absolute; left:32px; top:32px;">
<img src="images/joystick-red.png"/>
</div>
</div>
</div>
<!-- bottom-right -->
<div class="regionUI" style="bottom: 10px; right: 10px;">
<div class="buttonUI" style="width: 128px; opacity:0.80;">
<img src="images/joystick-base.png"/>
<div id="stick2" style="position: absolute; left:32px; top:32px;">
<img src="images/joystick-blue.png"/>
</div>
</div>
</div>
</div>
<script>
// need to run javascript code after a-scene entities and components are loaded
AFRAME.registerComponent('screen-controls',
{
init: function ()
{
this.component = document.getElementById("camera").components["extended-wasd-controls"];
this.joystick1 = new Joystick("stick1", 64, 8);
this.joystick2 = new Joystick("stick2", 64, 8);
},
tick: function(time, deltaTime)
{
// console.log( joystick1.value )
// console.log( this.component.movePercent )
this.component.movePercent.x = this.joystick1.value.x;
this.component.movePercent.z = -this.joystick1.value.y;
this.component.rotatePercent.x = -this.joystick2.value.y;
this.component.rotatePercent.y = -this.joystick2.value.x;
}
});
</script>
<!--
disable press "F" to enter fullscreen mode
disable WASD controls attached to default camera
-->
<a-scene
environment="preset: arches; shadow: true;"
keyboard-shortcuts="enterVR: false;"
vr-mode-ui="enabled: false;"
screen-controls>
<!-- no look controls; control angle with second joystick -->
<a-entity id="camera" camera
position="0 1.6 0"
extended-wasd-controls="flyEnabled: true; inputType: joystick;">
</a-entity>
</a-scene>
</body>
</html>