@duyquangnvx/pixi-game-engine 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,75 +1,75 @@
1
- # @duyquangnvx/pixi-game-engine
2
-
3
- Full-featured PixiJS v7 game engine with TypeScript support.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pnpm add @duyquangnvx/pixi-game-engine
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```typescript
14
- import { Engine, Scene, PIXI } from '@duyquangnvx/pixi-game-engine';
15
-
16
- class GameScene extends Scene {
17
- private player!: PIXI.Sprite;
18
-
19
- onEnter() {
20
- this.player = new PIXI.Graphics();
21
- this.player.beginFill(0x4ecca3);
22
- this.player.drawRect(-25, -25, 50, 50);
23
- this.player.x = Engine.screen.width / 2;
24
- this.player.y = Engine.screen.height / 2;
25
- this.addChild(this.player);
26
- }
27
-
28
- onUpdate(delta: number) {
29
- const { keyboard } = Engine.input;
30
-
31
- if (keyboard.isDown('ArrowLeft')) this.player.x -= 5 * delta;
32
- if (keyboard.isDown('ArrowRight')) this.player.x += 5 * delta;
33
- if (keyboard.isDown('ArrowUp')) this.player.y -= 5 * delta;
34
- if (keyboard.isDown('ArrowDown')) this.player.y += 5 * delta;
35
- }
36
-
37
- onExit() {}
38
- }
39
-
40
- Engine.init({
41
- width: 800,
42
- height: 600,
43
- backgroundColor: 0x1a1a2e,
44
- });
45
-
46
- document.body.appendChild(Engine.view as HTMLCanvasElement);
47
- Engine.scenes.add('game', GameScene);
48
- Engine.scenes.start('game');
49
- ```
50
-
51
- ## Features
52
-
53
- | Feature | Module | Description |
54
- |---------|--------|-------------|
55
- | Scenes | `SceneManager` | Scene lifecycle, transitions |
56
- | Input | `InputManager` | Keyboard, mouse, touch, gamepad |
57
- | Assets | `AssetManager` | Manifest-based loading |
58
- | Sound | `SoundManager` | @pixi/sound wrapper |
59
- | Particles | `ParticleManager` | @pixi/particle-emitter |
60
- | Tweens | `TweenManager` | GSAP + PixiPlugin |
61
- | UI | `UIManager` | @pixi/ui components |
62
- | Spine | `SpineManager` | pixi-spine animations |
63
-
64
- ## Dependencies
65
-
66
- - pixi.js ^7.4.2
67
- - @pixi/sound ^5.2.3
68
- - @pixi/particle-emitter ^5.0.10
69
- - @pixi/ui ^1.2.4
70
- - pixi-spine ^4.0.5
71
- - gsap ^3.12.x
72
-
73
- ## License
74
-
75
- MIT
1
+ # @duyquangnvx/pixi-game-engine
2
+
3
+ Full-featured PixiJS v7 game engine with TypeScript support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @duyquangnvx/pixi-game-engine
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Engine, Scene, PIXI } from '@duyquangnvx/pixi-game-engine';
15
+
16
+ class GameScene extends Scene {
17
+ private player!: PIXI.Sprite;
18
+
19
+ onEnter() {
20
+ this.player = new PIXI.Graphics();
21
+ this.player.beginFill(0x4ecca3);
22
+ this.player.drawRect(-25, -25, 50, 50);
23
+ this.player.x = Engine.screen.width / 2;
24
+ this.player.y = Engine.screen.height / 2;
25
+ this.addChild(this.player);
26
+ }
27
+
28
+ onUpdate(delta: number) {
29
+ const { keyboard } = Engine.input;
30
+
31
+ if (keyboard.isDown('ArrowLeft')) this.player.x -= 5 * delta;
32
+ if (keyboard.isDown('ArrowRight')) this.player.x += 5 * delta;
33
+ if (keyboard.isDown('ArrowUp')) this.player.y -= 5 * delta;
34
+ if (keyboard.isDown('ArrowDown')) this.player.y += 5 * delta;
35
+ }
36
+
37
+ onExit() {}
38
+ }
39
+
40
+ Engine.init({
41
+ width: 800,
42
+ height: 600,
43
+ backgroundColor: 0x1a1a2e,
44
+ });
45
+
46
+ document.body.appendChild(Engine.view as HTMLCanvasElement);
47
+ Engine.scenes.add('game', GameScene);
48
+ Engine.scenes.start('game');
49
+ ```
50
+
51
+ ## Features
52
+
53
+ | Feature | Module | Description |
54
+ |---------|--------|-------------|
55
+ | Scenes | `SceneManager` | Scene lifecycle, transitions |
56
+ | Input | `InputManager` | Keyboard, mouse, touch, gamepad |
57
+ | Assets | `AssetManager` | Manifest-based loading |
58
+ | Sound | `SoundManager` | @pixi/sound wrapper |
59
+ | Particles | `ParticleManager` | @pixi/particle-emitter |
60
+ | Tweens | `TweenManager` | GSAP + PixiPlugin |
61
+ | UI | `UIManager` | @pixi/ui components |
62
+ | Spine | `SpineManager` | pixi-spine animations |
63
+
64
+ ## Dependencies
65
+
66
+ - pixi.js ^7.4.2
67
+ - @pixi/sound ^5.2.3
68
+ - @pixi/particle-emitter ^5.0.10
69
+ - @pixi/ui ^1.2.4
70
+ - pixi-spine ^4.0.5
71
+ - gsap ^3.12.x
72
+
73
+ ## License
74
+
75
+ MIT
package/dist/index.cjs CHANGED
@@ -1453,10 +1453,32 @@ var SpineManager = class {
1453
1453
  fromData(skeletonData) {
1454
1454
  return new import_pixi_spine2.Spine(skeletonData);
1455
1455
  }
1456
- /** Play an animation on a Spine instance */
1457
- play(spine, animationName, loop = true, trackIndex = 0) {
1456
+ /** Play an animation on a Spine instance.
1457
+ * By default skips if the same animation is already playing (avoids restart).
1458
+ * Pass `force: true` to restart from frame 0. */
1459
+ play(spine, animationName, loop = true, trackIndex = 0, options) {
1460
+ if (!options?.force) {
1461
+ const current = spine.state.tracks[trackIndex];
1462
+ if (current?.animation?.name === animationName) return;
1463
+ }
1458
1464
  spine.state.setAnimation(trackIndex, animationName, loop);
1459
1465
  }
1466
+ /** Play a non-looping animation and resolve when it completes. */
1467
+ playOnce(spine, animationName, trackIndex = 0) {
1468
+ return new Promise((resolve) => {
1469
+ spine.state.setAnimation(trackIndex, animationName, false);
1470
+ const listener = {
1471
+ complete: (entry) => {
1472
+ const track = entry;
1473
+ if (track.animation?.name === animationName) {
1474
+ spine.state.removeListener(listener);
1475
+ resolve();
1476
+ }
1477
+ }
1478
+ };
1479
+ spine.state.addListener(listener);
1480
+ });
1481
+ }
1460
1482
  /** Add an animation to the queue */
1461
1483
  queue(spine, animationName, loop = false, delay = 0, trackIndex = 0) {
1462
1484
  spine.state.addAnimation(trackIndex, animationName, loop, delay);
@@ -1490,6 +1512,12 @@ var SpineManager = class {
1490
1512
  setSpeed(spine, speed) {
1491
1513
  spine.state.timeScale = speed;
1492
1514
  }
1515
+ /** Clear tracks, remove listeners, and destroy the spine instance. */
1516
+ destroy(spine) {
1517
+ spine.state.clearTracks();
1518
+ spine.state.clearListeners();
1519
+ spine.destroy({ children: true });
1520
+ }
1493
1521
  };
1494
1522
 
1495
1523
  // src/ui/toast/toast-manager.ts
@@ -2617,6 +2645,7 @@ var Engine = class _Engine {
2617
2645
  _Engine.onSceneChange.clear();
2618
2646
  _Engine._app.destroy(true, { children: true, texture: true });
2619
2647
  PIXI10.Assets.reset();
2648
+ PIXI10.Cache.reset();
2620
2649
  _Engine._isRunning = false;
2621
2650
  _Engine._initialized = false;
2622
2651
  }