-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
171 lines (122 loc) · 5.21 KB
/
index.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Joycon.js</title>
<meta charset="UTF-8">
<meta property="og:title" content="Joycon.js">
<meta property="og:locale" content="en_US">
<meta name="description" content="Add controller functionality to your JavaScript game.">
<meta property="og:description" content="Add controller functionality to your JavaScript game.">
<link rel="canonical" href="https://joycon.js.org/">
<meta property="og:url" content="https://joycon.js.org/">
<meta property="og:site_name" content="Joycon.js">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary">
<meta property="twitter:title" content="Joycon.js">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preload" href="https://fonts.googleapis.com/css?family=Inter:400,700&display=swap" as="style" type="text/css" crossorigin="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#157878">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="stylesheet" href="/homepage/style.css">
<link rel="shortcut icon" type="image/svg" href="/icon.svg">
</head>
<body ontouchstart="">
<header class="page-header" role="banner">
<h1 class="project-name">Joycon.js</h1>
<h2 class="project-tagline">Add controller functionality to your JavaScript game.</h2>
<a href="https://github.com/benhatsor/joycon.js" class="btn">View on GitHub</a>
</header>
<main id="content" class="main-content" role="main">
<h1 id="-joyconjs"><img src="icon.svg" width="30px"> Joycon.js</h1>
<ul>
<li>Supports PlayStation & Xbox</li>
<li><a href="#api">Really simple API</a></li>
<li><a href="/Joycon.min.js">~2.5KB minified</a></li>
<li>Vibration support</li>
</ul>
<h1 id="get-it">Get it</h1>
<p>Add this line to the <code class="language-plaintext highlighter-rouge"><body></code>:</p>
<pre><code class="language-HTML"><script src="https://joycon.js.org/Joycon.min.js"></script>
</code></pre>
<p>Here’s a <a href="https://cde.run/benhatsor/joycon.js/demo.html">demo.</a></p>
<h1 id="api">API</h1>
<h2 id="buttons">Buttons</h2>
<pre><code class="language-JS">const controllers = Joycon.controllers;
controllers.on.press('start', (value) => {
console.log('pressed start!', value); // value is 0 to 1
});
</code></pre>
<p>Button can be <code class="language-plaintext highlighter-rouge">a</code>, <code class="language-plaintext highlighter-rouge">b</code>, <code class="language-plaintext highlighter-rouge">x</code>, <code class="language-plaintext highlighter-rouge">y</code>, <code class="language-plaintext highlighter-rouge">start</code>, <code class="language-plaintext highlighter-rouge">left-trigger</code>, etc. (<a href="#button-list">full list below</a>)</p>
<h2 id="joystick">Joystick</h2>
<pre><code class="language-JS">const controllers = Joycon.controllers;
controllers.on.move('left-joystick', (value) => {
console.log('moved left joystick!', value.x, value.y); // value is -1 to 1 down/right
});
</code></pre>
<p>Also <code class="language-plaintext highlighter-rouge">right-joystick</code>.</p>
<h2 id="controller-connected">Controller connect</h2>
<pre><code class="language-JS">const controllers = Joycon.controllers;
controllers.on.connect((controller) => {
console.log('controller connected!', controller);
});
controllers.on.disconnect((controller) => {
console.log('controller disconnected!', controller);
});
</code></pre>
<h2 id="vibrate">Vibrate</h2>
<pre><code class="language-JS">const controllers = Joycon.controllers;
// preset can be mild, medium or strong
controllers.vibrate({ preset: 'medium' }, 250); // -> time in ms
// or you can choose your own values
controllers.vibrate({
mildMotorIntensity: 0.5,
strongMotorIntensity: 0.5
}, 250);
</code></pre>
<h2 id="remove-a-listener">Remove listener</h2>
<pre><code class="language-JS">const controllers = Joycon.controllers;
controllers.removeListener('left-trigger');
</code></pre>
<p>Remove Joystick <code class="language-plaintext highlighter-rouge">move</code> listeners with <code class="language-plaintext highlighter-rouge">left-joystick-move</code>.<br>
Remove controller <code class="language-plaintext highlighter-rouge">connect</code> listeners with <code class="language-plaintext highlighter-rouge">controller-connect</code>.</p>
<h1 id="button-list">Button list</h1>
<table>
<tbody>
<tr>
<td>a</td>
<td>left-shoulder</td>
<td>select</td>
<td>dpad-up</td>
<td>home</td>
</tr>
<tr>
<td>b</td>
<td>right-shoulder</td>
<td>start</td>
<td>dpad-down</td>
<td>share</td>
</tr>
<tr>
<td>x</td>
<td>left-trigger</td>
<td>left-joystick</td>
<td>dpad-left</td>
<td> </td>
</tr>
<tr>
<td>y</td>
<td>right-trigger</td>
<td>right-joystick</td>
<td>dpad-right</td>
<td> </td>
</tr>
</tbody>
</table>
<p><a href="#buttons">See above</a> on how to use these.</p>
<h1 id="license">License</h1>
<p><a href="/LICENSE">MIT</a></p>
<hr>
<p>Thanks for coming by!</p>
</main>
</body></html>