Skip to content

Commit 7b00b11

Browse files
committed
update engine
1 parent fd35757 commit 7b00b11

10 files changed

+119
-106
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LITECANVAS PLAYGROUND
22

3-
Online playground for [litecanvas](https://github.com/litecanvas/game-engine) game engine.
3+
Online playground for [Litecanvas](https://github.com/litecanvas/game-engine) game engine.
44

55
Try on https://litecanvas.js.org/
66

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/about.html

+91-86
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,11 @@ <h1>LITECANVAS</h1>
149149
</header>
150150

151151
<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.
155153
</p>
156154

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>
160157
</p>
161158

162159
<p id="install">
@@ -166,28 +163,32 @@ <h1>LITECANVAS</h1>
166163
>
167164
</p>
168165

166+
<p id="install">
167+
<strong>NPM</strong>:
168+
<code onclick="selectText(this)">npm install litecanvas</code>
169+
</p>
170+
169171
<p>
170172
<button class="no-print" onclick="window.print()">Print PDF</button>
171173
</p>
172174

173175
<nav class="no-print">
174176
<strong>API</strong>: <a href="#colors">Colors</a> |
175177
<a href="#settings">Configuration</a> |
178+
<a href="#globals">Globals</a> |
176179
<a href="#drawing">Drawing</a> |
177180
<a href="#sound">Sound</a> |
178181
<a href="#keyboard">Keyboard</a> |
179182
<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>
184184
</nav>
185185

186186
<h2>Basic boilerplate</h2>
187187

188188
<pre><code class="language-typescript">litecanvas({
189189
loop: {
190-
init, update, draw, resized, tap, tapping, untap, tapped
190+
init, update, draw, resized,
191+
tap, tapping, untap, tapped
191192
}
192193
})
193194

@@ -206,7 +207,7 @@ <h2>Basic boilerplate</h2>
206207

207208
function resized() {
208209
// called when the browser was resized
209-
// always called once before init()
210+
// also called once before init()
210211
}
211212

212213
function tap(x, y, tapId) {
@@ -273,11 +274,12 @@ <h2><a id="settings">Game Configuration</a></h2>
273274
settings.width = null
274275
settings.height = settings.width || null
275276

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.
278279
settings.pauseOnBlur = true
279280

280-
// scale the canvas
281+
// Determines whether the canvas should
282+
// scale to fill the canvas
281283
settings.autoscale = true
282284

283285
// target FPS
@@ -286,10 +288,12 @@ <h2><a id="settings">Game Configuration</a></h2>
286288
// enable smooth drawing
287289
settings.antialias = false
288290

289-
// disables antialias and force integer scales
291+
// disables antialias
292+
// and force the autoscale to use integers
290293
settings.pixelart = false
291294

292-
// export all functions to global scope
295+
// exposes all methods and properties (see below)
296+
// in the global scope
293297
settings.global = true
294298

295299
// set to `false` to disable the default tap handler
@@ -300,6 +304,47 @@ <h2><a id="settings">Game Configuration</a></h2>
300304
// useful to create your own keyboard handler
301305
settings.keyboardEvents = true</code></pre>
302306

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+
303348
<h2><a id="drawing">Functions for Drawing</a></h2>
304349

305350
<pre><code class="language-typescript">/**
@@ -338,16 +383,16 @@ <h2><a id="drawing">Functions for Drawing</a></h2>
338383
* TEXT DRAWING-RELATED FUNCTIONS
339384
*/
340385

341-
// draw a text
386+
// Draw a text
342387
text(x, y, text, color? = 3): void
343388

344-
// set the text alignment and baseline
389+
// Sets the text alignment and baseline
345390
// default values: align = 'start', baseline = 'top'
346391
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
347392
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
348393
textalign(align: string, baseline: string): void
349394

350-
// set the font family for texts
395+
// Sets the font family for texts
351396
textfont(fontName: string): void
352397

353398
// Sets the font size (default: 32)
@@ -403,30 +448,30 @@ <h2><a id="drawing">Functions for Drawing</a></h2>
403448
// Adds a rotation to the transformation matrix
404449
rotate(radians: number): void
405450

406-
// update the transformation matrix
451+
// Updates the transformation matrix
407452
// when `resetFirst = true` uses `context.setTransform()`
408453
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
409454
// when `resetFirst = false` uses `context.transform()`
410455
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/transform
411456
transform(a, b, c, d, e, f, resetFirst = true): void
412457

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
414459
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
415460
alpha(value: number): void
416461

417-
// fills the current path
462+
// Fills the current path
418463
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fill
419464
fill(color: number, path?: Path2D): void
420465

421-
// outlines the current path
466+
// Outlines the current path
422467
// see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/stroke
423468
stroke(color: number, path?: Path2D): void
424469

425-
// create (or clone) a Path2D instance
470+
// Create (or clone) a Path2D instance
426471
// see: https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
427472
path(arg?: Path2D | string): Path2D
428473

429-
// create a clipping region
474+
// Create a clipping region
430475
// see: https://github.com/litecanvas/game-engine/blob/main/samples/clip/clip.js
431476
// note: before call `clip()` you must save the context using `push()` and `pop()`
432477
clipcirc(path: Path2D)</code></pre>
@@ -564,66 +609,9 @@ <h2><a id="math">Math</a></h2>
564609

565610
// Check a collision between two circles.
566611
// 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>
568613

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>
627615

628616
<pre><code class="language-typescript">// Loads a plugin.
629617
// 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>
636624
// example: getcolor(0) returns "#111"
637625
getcolor(index: number): string
638626

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+
639634
// Resizes the game canvas.
640635
// 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>
642647

643648
<h2><a id="advanced">Playground Features</a></h2>
644649

public/app.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
>
3131
<strong
3232
><a href="https://github.com/litecanvas/game-engine"
33-
>litecanvas</a
33+
>Litecanvas</a
3434
></strong
3535
>
36-
is a lightweight HTML5 canvas engine suitable for small games and
37-
animations for people who enjoy coding: there is no fancy interface, no
38-
visual helpers, no gui tools... just coding.
36+
is a lightweight HTML5 canvas engine suitable for small web games,
37+
prototypes, game jams, animations, creative programming, learning game
38+
programming and game design, etc. Just install our NPM package or
39+
load/download the CDN by adding it as a script tag in your HTML.
3940
</p>
4041
<div class="top-bar">
4142
<button type="button" id="play" hidden>

public/litecanvas.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/manifest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "litecanvas",
3-
"short_name": "litecanvas",
4-
"id": "litecanvas",
5-
"description": "litecanvas is a lightweight HTML5 canvas engine suitable for small games and animations for people who enjoy coding: there is no fancy interface, no visual helpers, no gui tools... just coding.",
2+
"name": "Litecanvas",
3+
"short_name": "Litecanvas",
4+
"id": "Litecanvas",
5+
"description": "Litecanvas is a lightweight HTML5 canvas engine suitable for small games and animations for people who enjoy coding: there is no fancy interface, no visual helpers, no gui tools... just coding.",
66
"start_url": ".",
77
"background_color": "#18161c",
88
"theme_color": "#18161c",

public/preview.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<html>
33
<head>
44
<meta charset="UTF-8" />
5+
<meta name="robots" content="noindex" />
56
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Preview</title>
7+
<title>Litecanvas Preview</title>
78
<style>
89
html,
910
body {

public/sw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2.23.1";
2+
const version = "2.24.0";
33

44
const precacheResources = [
55
"/",

src/completions.js

+6
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ export default function customCompletions(context) {
475475
detail: "(width, height)",
476476
info: "resizes the game canvas",
477477
},
478+
{
479+
label: "setfps",
480+
type: "function",
481+
apply: "setfps(",
482+
detail: "(value)",
483+
},
478484

479485
// asset loader plugin
480486
{

0 commit comments

Comments
 (0)