-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
kontra.html
188 lines (119 loc) · 6.32 KB
/
kontra.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
<head>
<title>Kontra.js – Kontra</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.22/webcomponents-lite.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.min.css">
<link rel="stylesheet" href="../styles.css">
<link rel="import" href="../components/main-nav.html">
<link rel="import" href="../components/code-output.html">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/components/prism-javascript.min.js"></script>
<script src="../js/kontra.js"></script>
</head>
<body>
<div class="content">
<main-nav></main-nav>
<main id="main">
<div>
<h1>Kontra</h1>
<p>The kontra library object. Typically you will call <a href="#init">kontra.init()</a> as the first thing and give it the canvas to use. This will allow all kontra objects to reference the canvas when created.</p>
<pre><code class="language-javascript">kontra.init();</code></pre>
<section class="toc">
<h2 id="toc"><a href="#toc" class="section-link">Table of Contents<span aria-hidden="true">#</span></a></h2>
<ul aria-labeledby="toc">
<li>
<ul>
<li><a href="#lifecycle">Lifecycle Events</a></li></li>
</ul>
</li>
<li>
<h3 id="properties">Properties</h3>
<ul aria-labeledby="properties">
<li><a href="#canvas">kontra​.canvas</a></li>
<li><a href="#context">kontra​.context</a></li>
<li><a href="assets">kontra​.assets</a></li>
<li><a href="keyboard">kontra​.keys</a></li>
<li><a href="plugin">kontra​.plugin</a></li>
<li><a href="pointer">kontra​.pointer</a></li>
<li><a href="store">kontra​.store</a></li>
</ul>
</li>
<li>
<h3 id="methods">Methods</h3>
<ul aria-labeledby="methods">
<li><a href="#emit">kontra​.emit(event[, ...args])</a></li>
<li><a href="#init">kontra​.init([canvas])</a></li>
<li><a href="#off">kontra​.off(event, callback)</a></li>
<li><a href="#on">kontra​.on(event, callback)</a></li>
<li><a href="animation">kontra​.animation(properties)</a></li>
<li><a href="gameLoop">kontra​.gameLoop(properties)</a></li>
<li><a href="pool">kontra​.pool(properties)</a></li>
<li><a href="quadtree">kontra​.quadtree(properties)</a></li>
<li><a href="sprite">kontra​.sprite(properties)</a></li>
<li><a href="spriteSheet">kontra​.spriteSheet(properties)</a></li>
<li><a href="tileEngine">kontra​.tileEngine(properties)</a></li>
<li><a href="vector">kontra​.vector(properties)</a></li>
</ul>
</li>
</ul>
</section>
<section>
<h2 id="lifecycle"><a href="#lifecycle" class="section-link">Lifecycle Events<span aria-hidden="true">#</span></a></h2>
<p>When Kontra is initialized, it will emit an <code>init</code> event.</p>
<pre><code class="language-javascript">kontra.on('init', (canvas) => {
// run code when Kontra is initialized
});</code></pre>
</section>
<section>
<h2 id="canvas"><a href="#canvas" class="section-link">kontra.canvas<span aria-hidden="true">#</span></a></h2>
<p>The main game canvas. By default, all kontra objects will use this canvas.</p>
</section>
<section>
<h2 id="context"><a href="#context" class="section-link">kontra.context<span aria-hidden="true">#</span></a></h2>
<p>The main game context. By default, all kontra objects will render to this context.</p>
</section>
<section>
<h2 id="emit"><a href="#emit" class="section-link">kontra​.emit(event[, ...args])<span aria-hidden="true">#</span></a></h2>
<dl>
<dt><strong>event</strong> <em>{string}</em></dt>
<dd>The name of the event to emit.</dd>
<dt><strong>args</strong> <em>{...*}</em></dt>
<dd>Arguments passed to all callbacks.</dd>
</dl>
<p>Emit an event and run all its callbacks, passing it any arguments.</p>
</section>
<section>
<h2 id="init"><a href="#init" class="section-link">kontra.init([canvas])<span aria-hidden="true">#</span></a></h2>
<dl>
<dt><strong>canvas</strong> <em>{string | HTMLCanvasElement}</em></dt>
<dd>The canvas for kontra to use. Can either be the id of the canvas element or the canvas element itself. Defaults to using the first canvas element on the page.</dd>
</dl>
<p>Initialize the library and set up the canvas. You should call this function first before creating any kontra objects.</p>
</section>
<section>
<h2 id="off"><a href="#off" class="section-link">kontra​.off(event, callback)<span aria-hidden="true">#</span></a></h2>
<dl>
<dt><strong>event</strong> <em>{string}</em></dt>
<dd>The name of the event to emit.</dd>
<dt><strong>callback</strong> <em>{function}</em></dt>
<dd>Function callback.</dd>
</dl>
<p>Remove the callback from the event so it will no longer be run when the event is emitted.</p>
</section>
<section>
<h2 id="on"><a href="#on" class="section-link">kontra​.on(event, callback)<span aria-hidden="true">#</span></a></h2>
<dl>
<dt><strong>event</strong> <em>{string}</em></dt>
<dd>The name of the event to emit.</dd>
<dt><strong>callback</strong> <em>{function}</em></dt>
<dd>Function callback.</dd>
</dl>
<p>Add the callback to the event so it will run when the event is emitted.</p>
</section>
</div>
</main>
</div>
</body>
</html>