Skip to content

Commit f1f4fbf

Browse files
committed
feat: add sprites and type sprite for kaboom engine
1 parent 3e9c8e8 commit f1f4fbf

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/public/sprite.png

8.24 KB
Loading

src/public/sprite2.png

6.27 KB
Loading

src/public/spritesheet.png

4.73 KB
Loading

src/scripts/kaboom.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class KaboomEngine extends Engine {
1515
width: this.width,
1616
height: this.height,
1717
});
18+
k.loadSprite('sprite', '/sprite.png');
1819
this.k = k;
1920

2021
// Clear the canvas
@@ -32,15 +33,21 @@ class KaboomEngine extends Engine {
3233
3 * Math.random() * rnd[Math.floor(Math.random() * 2)],
3334
3 * Math.random() * rnd[Math.floor(Math.random() * 2)],
3435
];
35-
const circle = k.add([
36-
k.pos(x, y),
37-
k.circle(size),
38-
k.opacity(this.type === 'stroke' ? 0 : 1),
39-
k.outline(
40-
1,
41-
this.type === 'stroke' ? k.rgb(255, 255, 255) : k.rgb(0, 0, 0)
42-
),
43-
]);
36+
let circle;
37+
if (this.type === 'sprite') {
38+
circle = k.add([k.sprite('sprite'), k.pos(x, y)]);
39+
} else {
40+
circle = k.add([
41+
k.pos(x, y),
42+
k.circle(size),
43+
k.opacity(this.type === 'stroke' ? 0 : 1),
44+
k.outline(
45+
1,
46+
this.type === 'stroke' ? k.rgb(255, 255, 255) : k.rgb(0, 0, 0)
47+
),
48+
]);
49+
}
50+
4451
particles[i] = { x, y, size: size, dx, dy, el: circle };
4552
}
4653
this.particles = particles;

0 commit comments

Comments
 (0)