Skip to content

Commit 4b354ba

Browse files
committed
update demo
1 parent 45feac0 commit 4b354ba

File tree

3 files changed

+49
-39
lines changed

3 files changed

+49
-39
lines changed

public/app.js

Lines changed: 24 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2025.06.11.0";
2+
const version = "2025.06.13.0";
33

44
const precacheResources = [
55
"/",

src/demo.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,40 @@ export default () =>
33
// Learn more tapping on the question mark (?) above.
44
// Join our discord: https://discord.com/invite/r2c3rGsvH3
55
6-
let x, y, size, speed, color
6+
// Start the engine
7+
litecanvas({
8+
loop: { init, update, draw, tapped },
9+
})
710
8-
litecanvas()
11+
let bg, color, radius, posx, posy
912
10-
// run once before the game starts
13+
// this function runs once at the beginning
1114
function init() {
12-
x = CX
13-
y = CY
14-
size = 32
15-
speed = 250
16-
color = 4
15+
bg = 0 // the color #0 (black)
16+
color = 3 // the color #3 (white)
17+
radius = W / 10 // the canvas width/10
18+
posx = CX // center X (or canvas width/2)
19+
posy = CY // center Y (or canvas width/2)
1720
}
1821
19-
// called when touches/clicks happens
20-
function tapped(tapx, tapy) {
21-
x = tapx
22-
y = tapy
22+
// this function detect clicks/touches
23+
function tapped(x, y) {
24+
// changes the circle position
25+
// based on the position of the tap
26+
posx = x
27+
posy = y
2328
}
2429
25-
// this function controls the game logic
30+
// put the game logic in this function
2631
function update(dt) {
27-
x += speed * dt * (iskeydown('D') - iskeydown('A'))
28-
y += speed * dt * (iskeydown('S') - iskeydown('W'))
32+
// make the circle falls 100 pixels per second
33+
posy += 200 * dt
2934
}
3035
31-
// this function render the game scene
36+
// put the game rendering in this function
3237
function draw() {
33-
cls(0)
34-
rectfill(x, y, size, size, color)
35-
text(0, 0, 'use WASD keys or taps/clicks')
38+
cls(bg) // clear the screen
39+
circfill(posx, posy, radius, color) // draw a circle
40+
text(10, 10, 'Tap anywhere') // draw a text
3641
}
3742
`;

0 commit comments

Comments
 (0)