game.nv
· 822 B · Text
Bruto
Playground
| 'DOCUMENTATION' | ~~
this game library lets you create a canvas that you can
update every frame . you can start a game like so :
// '' start a 400 by 600 game
and you can create a game loop that updates like this :
/ '' game loop $dt
/ '' do something
'' do something else
'' next frame
|| '@include' (
lib/gas.nv
lib/platforms/browser_dom.nv
lib/platforms/browser_game.nv
)
| '' start a $x by $y game
| '@graphics' . canvas init canvas . set resolution $x $y
'DOM' ( <query canvas <style display = block margin = [1rem auto] > > )
'' game loop 0
| '' next frame
| '' @gas is now 50000
'@js' window.requestAnimationFrame(nextFrame);
|| '@js'
let then = 0;
const nextFrame = (now) => {
const dt = now - then;
then = now;
f("", "game", "loop", dt);
me.run();
}
1 | | 'DOCUMENTATION' | ~~ |
2 | this game library lets you create a canvas that you can |
3 | update every frame . you can start a game like so : |
4 | |
5 | // '' start a 400 by 600 game |
6 | |
7 | and you can create a game loop that updates like this : |
8 | |
9 | / '' game loop $dt |
10 | / '' do something |
11 | '' do something else |
12 | '' next frame |
13 | |
14 | |
15 | || '@include' ( |
16 | lib/gas.nv |
17 | lib/platforms/browser_dom.nv |
18 | lib/platforms/browser_game.nv |
19 | ) |
20 | |
21 | | '' start a $x by $y game |
22 | | '@graphics' . canvas init canvas . set resolution $x $y |
23 | 'DOM' ( <query canvas <style display = block margin = [1rem auto] > > ) |
24 | '' game loop 0 |
25 | |
26 | | '' next frame |
27 | | '' @gas is now 50000 |
28 | '@js' window.requestAnimationFrame(nextFrame); |
29 | |
30 | || '@js' |
31 | let then = 0; |
32 | const nextFrame = (now) => { |
33 | const dt = now - then; |
34 | then = now; |
35 | f("", "game", "loop", dt); |
36 | me.run(); |
37 | } |