Mercurial > malikania
comparison examples/01-bouncing/client.js @ 26:56cc058200b5
Client: add basic mlk-client code with an example, #472
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 08 Apr 2016 14:16:47 +0200 |
parents | |
children | 0a1adf7dcca0 |
comparison
equal
deleted
inserted
replaced
25:dc47ce56ce36 | 26:56cc058200b5 |
---|---|
1 var x = 0; | |
2 var y = 0; | |
3 | |
4 var dx = 1; | |
5 var dy = 1; | |
6 | |
7 var font; | |
8 var clip; | |
9 | |
10 function start(window) | |
11 { | |
12 font = new Malikania.Font("fonts/DejaVuSans.ttf", 10); | |
13 clip = font.clip("Malikania"); | |
14 | |
15 x = (640 / 2) - (clip.width / 2); | |
16 y = (480 / 2) - (clip.height / 2); | |
17 } | |
18 | |
19 function update() | |
20 { | |
21 x += dx; | |
22 y += dy; | |
23 | |
24 if (x >= 640 - clip.width) | |
25 dx = -1; | |
26 else if (x <= 0) | |
27 dx = 1; | |
28 if (y >= 480 - clip.height) | |
29 dy = -1; | |
30 else if (y <= 0) | |
31 dy = 1; | |
32 } | |
33 | |
34 function draw(window) | |
35 { | |
36 window.setDrawingColor('lightskyblue'); | |
37 window.clear(); | |
38 window.setDrawingColor('white'); | |
39 window.drawText('Malikania', font, { x: x, y: y }); | |
40 window.present(); | |
41 } |