Skip to content

Commit afb90d6

Browse files
committed
feat: add type sprite on pixi engine
1 parent f1f4fbf commit afb90d6

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/scripts/pixi.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class PixiEngine extends Engine {
55
constructor() {
66
super();
77
}
8-
init() {
8+
async init() {
99
super.init();
1010

1111
// Clear the canvas
@@ -20,7 +20,6 @@ class PixiEngine extends Engine {
2020
backgroundColor: 0x1a1a1a,
2121
antialias: true,
2222
});
23-
console.log(this.app.renderer);
2423
this.app.view.classList.add('canvas');
2524

2625
// Update canvas with application view
@@ -29,6 +28,9 @@ class PixiEngine extends Engine {
2928
main.appendChild(this.app.view);
3029

3130
// Particle creation
31+
if (this.type === 'sprite') {
32+
this.texture = PIXI.Texture.from('/sprite.png');
33+
}
3234
const particles = new Array(this.count);
3335
const rnd = [1, -1];
3436
for (let i = 0; i < this.count; i++) {
@@ -39,15 +41,20 @@ class PixiEngine extends Engine {
3941
3 * Math.random() * rnd[Math.floor(Math.random() * 2)],
4042
3 * Math.random() * rnd[Math.floor(Math.random() * 2)],
4143
];
42-
const particle = new PIXI.Graphics();
43-
if (this.type === 'stroke') {
44-
particle.lineStyle(1, 0xffffff, 1);
45-
particle.drawCircle(-size / 2, -size / 2, size, 0, Math.PI);
46-
} else if (this.type === 'fill') {
47-
particle.beginFill(0xffffff);
48-
particle.lineStyle(1, 0x000000, 1);
49-
particle.drawCircle(-size / 2, -size / 2, size, 0, Math.PI);
50-
particle.endFill();
44+
let particle;
45+
if (this.type === 'sprite') {
46+
particle = new PIXI.Sprite(this.texture);
47+
} else {
48+
particle = new PIXI.Graphics();
49+
if (this.type === 'stroke') {
50+
particle.lineStyle(1, 0xffffff, 1);
51+
particle.drawCircle(-size / 2, -size / 2, size, 0, Math.PI);
52+
} else if (this.type === 'fill') {
53+
particle.beginFill(0xffffff);
54+
particle.lineStyle(1, 0x000000, 1);
55+
particle.drawCircle(-size / 2, -size / 2, size, 0, Math.PI);
56+
particle.endFill();
57+
}
5158
}
5259
particle.position.set(x, y);
5360
this.app.stage.addChild(particle);

0 commit comments

Comments
 (0)