···
1
1
+
<html>
2
2
+
<head>
3
3
+
<meta charset="UTF-8" />
4
4
+
<meta
5
5
+
name="viewport"
6
6
+
content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
7
7
+
/>
8
8
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/7.1.0/pixi.min.js"></script>
9
9
+
</head>
10
10
+
<body style="overflow: hidden">
11
11
+
<script>
12
12
+
class PiXI_SCAFFOLD {
13
13
+
constructor() {
14
14
+
let w = window.innerWidth,
15
15
+
h = window.innerHeight;
16
16
+
17
17
+
this.app = new PIXI.Application({
18
18
+
width: w,
19
19
+
height: h,
20
20
+
antialias: true,
21
21
+
transparent: false,
22
22
+
resolution: 1,
23
23
+
});
24
24
+
this.keys = {};
25
25
+
document.addEventListener("keydown", this.keyDown.bind(this));
26
26
+
document.addEventListener("keyup", this.keyUp.bind(this));
27
27
+
window.addEventListener("resize", this.windowResized.bind(this));
28
28
+
29
29
+
this.setupScene();
30
30
+
this.app.view.style.position = "absolute";
31
31
+
this.app.view.style.top = "0px";
32
32
+
this.app.view.style.left = "0px";
33
33
+
34
34
+
document.body.appendChild(this.app.view);
35
35
+
let ticker = PIXI.Ticker.shared;
36
36
+
ticker.add(this.animate.bind(this));
37
37
+
}
38
38
+
39
39
+
setupScene() {
40
40
+
/* setup your scene here */
41
41
+
let radius =
42
42
+
Math.min(this.app.screen.width, this.app.screen.height) / 3;
43
43
+
/* START */
44
44
+
this.circle = new PIXI.Graphics();
45
45
+
this.circle.beginFill(0xaa0000);
46
46
+
this.circle.drawCircle(0, 0, radius / 5);
47
47
+
this.circle.endFill();
48
48
+
this.app.stage.addChild(this.circle);
49
49
+
50
50
+
this.circle.x = this.app.screen.width / 2 + radius * Math.cos(0);
51
51
+
this.circle.y = this.app.screen.height / 2 + radius * Math.sin(0);
52
52
+
/* END */
53
53
+
}
54
54
+
animate() {
55
55
+
/* Update your scene here */
56
56
+
let elapsed = PIXI.Ticker.shared.elapsedMS / 1000.0;
57
57
+
let total = PIXI.Ticker.shared.lastTime / 1000.0;
58
58
+
59
59
+
/* START */
60
60
+
let radius =
61
61
+
Math.min(this.app.screen.width, this.app.screen.height) / 3;
62
62
+
this.circle.x = this.app.screen.width / 2 + radius * Math.cos(total);
63
63
+
this.circle.y = this.app.screen.height / 2 + radius * Math.sin(total);
64
64
+
/* END */
65
65
+
}
66
66
+
67
67
+
windowResized() {
68
68
+
this.app.renderer.resize(window.innerWidth, window.innerHeight);
69
69
+
}
70
70
+
keyDown(event) {
71
71
+
this.keys[event.key] = true;
72
72
+
}
73
73
+
keyUp(event) {
74
74
+
this.keys[event.key] = false;
75
75
+
}
76
76
+
}
77
77
+
let app = new PiXI_SCAFFOLD();
78
78
+
</script>
79
79
+
</body>
80
80
+
</html>