@@ -149,14 +149,11 @@ <h1>LITECANVAS</h1>
149
149
</ header >
150
150
151
151
< p >
152
- Lightweight HTML5 canvas engine suitable for small games and animations
153
- for people who enjoy coding: there is no fancy interface, no visual
154
- helpers, no gui tools... just coding.
152
+ Litecanvas is a lightweight HTML5 canvas engine suitable for small web games, prototypes, game jams, animations, creative programming, learning game programming and game design, etc. Just install our NPM package or load/download the CDN by adding it as a script tag in your HTML.
155
153
</ p >
156
154
157
- < p id ="install ">
158
- < strong > NPM</ strong > :
159
- < code onclick ="selectText(this) "> npm i litecanvas</ code >
155
+ < p >
156
+ < strong > This project is still under development. All feedback is appreciated! For bugs, suggestions or contribuitions open a issue in our < a href ="https://github.com/litecanvas/game-engine "> Github Repository</ a > .</ strong >
160
157
</ p >
161
158
162
159
< p id ="install ">
@@ -166,28 +163,32 @@ <h1>LITECANVAS</h1>
166
163
>
167
164
</ p >
168
165
166
+ < p id ="install ">
167
+ < strong > NPM</ strong > :
168
+ < code onclick ="selectText(this) "> npm install litecanvas</ code >
169
+ </ p >
170
+
169
171
< p >
170
172
< button class ="no-print " onclick ="window.print() "> Print PDF</ button >
171
173
</ p >
172
174
173
175
< nav class ="no-print ">
174
176
< strong > API</ strong > : < a href ="#colors "> Colors</ a > |
175
177
< a href ="#settings "> Configuration</ a > |
178
+ < a href ="#globals "> Globals</ a > |
176
179
< a href ="#drawing "> Drawing</ a > |
177
180
< a href ="#sound "> Sound</ a > |
178
181
< a href ="#keyboard "> Keyboard</ a > |
179
182
< a href ="#math "> Math</ a > |
180
- < a href ="#globals "> Globals</ a > |
181
- < a href ="#events "> Events</ a > |
182
- < a href ="#plugin-api "> Plugin API</ a > |
183
- < a href ="#advanced "> Advanced</ a >
183
+ < a href ="#engine-api "> Engine</ a >
184
184
</ nav >
185
185
186
186
< h2 > Basic boilerplate</ h2 >
187
187
188
188
< pre > < code class ="language-typescript "> litecanvas({
189
189
loop: {
190
- init, update, draw, resized, tap, tapping, untap, tapped
190
+ init, update, draw, resized,
191
+ tap, tapping, untap, tapped
191
192
}
192
193
})
193
194
@@ -206,7 +207,7 @@ <h2>Basic boilerplate</h2>
206
207
207
208
function resized() {
208
209
// called when the browser was resized
209
- // always called once before init()
210
+ // also called once before init()
210
211
}
211
212
212
213
function tap(x, y, tapId) {
@@ -273,11 +274,12 @@ <h2><a id="settings">Game Configuration</a></h2>
273
274
settings.width = null
274
275
settings.height = settings.width || null
275
276
276
- // Determines whether the game loop should be paused
277
- // when the "blur" event happens.
277
+ // Determines whether the game loop should
278
+ // be paused when the "blur" event happens.
278
279
settings.pauseOnBlur = true
279
280
280
- // scale the canvas
281
+ // Determines whether the canvas should
282
+ // scale to fill the canvas
281
283
settings.autoscale = true
282
284
283
285
// target FPS
@@ -286,10 +288,12 @@ <h2><a id="settings">Game Configuration</a></h2>
286
288
// enable smooth drawing
287
289
settings.antialias = false
288
290
289
- // disables antialias and force integer scales
291
+ // disables antialias
292
+ // and force the autoscale to use integers
290
293
settings.pixelart = false
291
294
292
- // export all functions to global scope
295
+ // exposes all methods and properties (see below)
296
+ // in the global scope
293
297
settings.global = true
294
298
295
299
// set to `false` to disable the default tap handler
@@ -300,6 +304,47 @@ <h2><a id="settings">Game Configuration</a></h2>
300
304
// useful to create your own keyboard handler
301
305
settings.keyboardEvents = true</ code > </ pre >
302
306
307
+ < h2 > < a id ="globals "> Global Variables</ a > </ h2 >
308
+
309
+ < pre > < code class ="language-typescript "> // the game canvas
310
+ CANVAS: HTMLCanvasElement
311
+
312
+ // the game screen width
313
+ WIDTH: number
314
+
315
+ // the game screen height
316
+ HEIGHT: number
317
+
318
+ // the center X of game screen
319
+ CENTERX: number
320
+
321
+ // the center Y of game screen
322
+ CENTERY: number
323
+
324
+ // the FPS meter
325
+ FPS: number
326
+
327
+ // the amount of time since the game started
328
+ ELAPSED: number
329
+
330
+ // the current mouse's X-position
331
+ // or -1 (if the mouse was not used or detected)
332
+ MOUSEX: number
333
+
334
+ // the current mouse's Y-position
335
+ // or -1 (if the mouse was not used or detected)
336
+ MOUSEY: number
337
+
338
+ // the default sound played in `sfx()`
339
+ DEFAULT_SFX: number[]
340
+
341
+ // Math constants
342
+ PI: number // approximately 3.14 radians (180º)
343
+
344
+ TWO_PI: number // approximately 6.28 radians (360º)
345
+
346
+ HALF_PI: number // approximately 1.57 radians (90º)</ code > </ pre >
347
+
303
348
< h2 > < a id ="drawing "> Functions for Drawing</ a > </ h2 >
304
349
305
350
< pre > < code class ="language-typescript "> /**
@@ -338,16 +383,16 @@ <h2><a id="drawing">Functions for Drawing</a></h2>
338
383
* TEXT DRAWING-RELATED FUNCTIONS
339
384
*/
340
385
341
- // draw a text
386
+ // Draw a text
342
387
text(x, y, text, color? = 3): void
343
388
344
- // set the text alignment and baseline
389
+ // Sets the text alignment and baseline
345
390
// default values: align = 'start', baseline = 'top'
346
391
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
347
392
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
348
393
textalign(align: string, baseline: string): void
349
394
350
- // set the font family for texts
395
+ // Sets the font family for texts
351
396
textfont(fontName: string): void
352
397
353
398
// Sets the font size (default: 32)
@@ -403,30 +448,30 @@ <h2><a id="drawing">Functions for Drawing</a></h2>
403
448
// Adds a rotation to the transformation matrix
404
449
rotate(radians: number): void
405
450
406
- // update the transformation matrix
451
+ // Updates the transformation matrix
407
452
// when `resetFirst = true` uses `context.setTransform()`
408
453
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
409
454
// when `resetFirst = false` uses `context.transform()`
410
455
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/transform
411
456
transform(a, b, c, d, e, f, resetFirst = true): void
412
457
413
- // set the alpha (opacity) value to apply when drawing new shapes and images
458
+ // Sets the alpha (opacity) value to apply when drawing new shapes and images
414
459
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
415
460
alpha(value: number): void
416
461
417
- // fills the current path
462
+ // Fills the current path
418
463
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fill
419
464
fill(color: number, path?: Path2D): void
420
465
421
- // outlines the current path
466
+ // Outlines the current path
422
467
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/stroke
423
468
stroke(color: number, path?: Path2D): void
424
469
425
- // create (or clone) a Path2D instance
470
+ // Create (or clone) a Path2D instance
426
471
// see: https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
427
472
path(arg?: Path2D | string): Path2D
428
473
429
- // create a clipping region
474
+ // Create a clipping region
430
475
// see: https://github.com/litecanvas/game-engine/blob/main/samples/clip/clip.js
431
476
// note: before call `clip()` you must save the context using `push()` and `pop()`
432
477
clipcirc(path: Path2D)</ code > </ pre >
@@ -564,66 +609,9 @@ <h2><a id="math">Math</a></h2>
564
609
565
610
// Check a collision between two circles.
566
611
// All arguments are required and must be numbers.
567
- colcirc(x1, y1, r1, x2, y2, r2): boolean
612
+ colcirc(x1, y1, r1, x2, y2, r2): boolean</ code > </ pre >
568
613
569
- // Sets the scale of the game's delta time (dt).
570
- // By default is equal to 1.
571
- // Values higher than 1 increase the speed of time,
572
- // while values smaller than 1 decrease it.
573
- // A value of 0 freezes time (equivalent to pausing).
574
- timescale(value: number): void</ code > </ pre >
575
-
576
- < h2 > < a id ="globals "> Global Variables</ a > </ h2 >
577
-
578
- < pre > < code class ="language-typescript "> // the game canvas
579
- CANVAS: HTMLCanvasElement
580
-
581
- // the game screen width
582
- WIDTH: number
583
-
584
- // the game screen height
585
- HEIGHT: number
586
-
587
- // the center X of game screen
588
- CENTERX: number
589
-
590
- // the center Y of game screen
591
- CENTERY: number
592
-
593
- // the FPS meter
594
- FPS: number
595
-
596
- // the amount of time since the game started
597
- ELAPSED: number
598
-
599
- // the current mouse's X-position
600
- // or -1 (if the mouse was not used or detected)
601
- MOUSEX: number
602
-
603
- // the current mouse's Y-position
604
- // or -1 (if the mouse was not used or detected)
605
- MOUSEY: number
606
-
607
- // the default sound played in `sfx()`
608
- DEFAULT_SFX: number[]
609
-
610
- // Math constants
611
- PI: number // approximately 3.14159 radians (180º)
612
-
613
- TWO_PI: number // approximately 6.28318 radians (360º)
614
-
615
- HALF_PI: number // approximately 1.57079 radians (90º)</ code > </ pre >
616
-
617
- < h2 > < a id ="events "> Event Emitter</ a > </ h2 >
618
-
619
- < pre > < code class ="language-typescript "> // Registers a game event callback and
620
- // returns a function that unregister this callback.
621
- listen(event: string, callback: Function): Function
622
-
623
- // Triggers a game event and call its registered callbacks.
624
- emit(event: string, arg1?, arg2?, arg3?, arg4?): void</ code > </ pre >
625
-
626
- < h2 > < a id ="plugin-api "> Plugin API</ a > </ h2 >
614
+ < h2 > < a id ="plugin-api "> Engine API</ a > </ h2 >
627
615
628
616
< pre > < code class ="language-typescript "> // Loads a plugin.
629
617
// see: https://github.com/litecanvas/game-engine/blob/main/samples/plugin-basics/plugin-basics.js
@@ -636,9 +624,26 @@ <h2><a id="plugin-api">Plugin API</a></h2>
636
624
// example: getcolor(0) returns "#111"
637
625
getcolor(index: number): string
638
626
627
+ // Registers a game event callback and
628
+ // returns a function that unregister this callback.
629
+ listen(event: string, callback: Function): Function
630
+
631
+ // Triggers a game event and call its registered callbacks.
632
+ emit(event: string, arg1?, arg2?, arg3?, arg4?): void
633
+
639
634
// Resizes the game canvas.
640
635
// Also, emits the "resized" (use `listen` to observe this event).
641
- resize(width: number, height: number): void</ code > </ pre >
636
+ resize(width: number, height: number): void
637
+
638
+ // Sets the scale of the game's delta time (dt).
639
+ // By default is equal to 1.
640
+ // Values higher than 1 increase the speed of time,
641
+ // while values smaller than 1 decrease it.
642
+ // A value of 0 freezes time (equivalent to pausing).
643
+ timescale(value: number): void
644
+
645
+ // Sets the target FPS at runtime
646
+ setfps(value: number): void</ code > </ pre >
642
647
643
648
< h2 > < a id ="advanced "> Playground Features</ a > </ h2 >
644
649
0 commit comments