-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
45 lines (38 loc) · 1.06 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as PIXI from 'pixi.js';
import TILEDGraphics from './TILEDGraphics';
window.onload = () => {
const path = 'assets/1v1/1v1_field.json';
const app = new PIXI.Application({ width: 800, height: 600 });
fetch(path).then(res => res.json()).then(tilemap => {
app.stage.addChild(new TILEDGraphics(tilemap, path));
});
document.body.appendChild(app.view);
const keys = {};
document.addEventListener('keydown', e => keys[e.key] = true);
document.addEventListener('keyup', e => keys[e.key] = false);
app.ticker.add(() => {
const v = 10;
if (keys['ArrowLeft'] || keys['a']) {
app.stage.x += v;
}
if (keys['ArrowRight'] || keys['d']) {
app.stage.x -= v;
}
if (keys['ArrowDown'] || keys['s']) {
app.stage.y -= v;
}
if (keys['ArrowUp'] || keys['w']) {
app.stage.y += v;
}
const zoom = 1.1;
if (keys['z'] || keys['y']) {
app.stage.scale.x *= zoom;
app.stage.scale.y *= zoom;
}
if (keys['x']) {
app.stage.scale.x /= zoom;
app.stage.scale.y /= zoom;
}
});
app.start();
}