@combos-fun/plugin-renderer-sprite-animation 0.0.44 → 0.0.46

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.
Files changed (2) hide show
  1. package/agent-skill.md +23 -56
  2. package/package.json +5 -5
package/agent-skill.md CHANGED
@@ -1,71 +1,38 @@
1
1
  # `@combos-fun/plugin-renderer-sprite-animation` — Agent notes
2
2
 
3
- Frame-based sprite animation for the 2D pipeline. Plays an ordered set of frames from a Texture Packer atlas as a flipbook animation.
4
-
5
- ## When to read
6
-
7
- Read for any frame-by-frame animation: character idle / run / attack loops, FX, particle bursts.
8
-
9
- ## Public API
3
+ Read only for flipbook playback of atlas frames. Use `Sprite` when exactly one atlas frame should be shown.
10
4
 
11
5
  ```ts
12
- import { SpriteAnimation, SpriteAnimationSystem, type SpriteAnimationParams } from '@combos-fun/plugin-renderer-sprite-animation';
6
+ import {
7
+ SpriteAnimation,
8
+ SpriteAnimationSystem,
9
+ type SpriteAnimationParams,
10
+ } from '@combos-fun/plugin-renderer-sprite-animation';
13
11
  ```
14
12
 
15
- `componentName = 'SpriteAnimation'`, `systemName = 'SpriteAnimation'` (class is `SpriteAnimationSystem` — use `game.getSystem(SpriteAnimationSystem)`, not the string).
16
-
17
- ### `SpriteAnimationParams`
13
+ `SpriteAnimation.componentName = 'SpriteAnimation'`; `SpriteAnimationSystem.systemName = 'SpriteAnimation'`.
18
14
 
19
- | Field | Type | Default | Notes |
20
- |-------|------|---------|-------|
21
- | `resource` | `string` | | Engine resource name registered with `RESOURCE_TYPE.SPRITE_ANIMATION`. `src` must include both `image` and `json`. |
22
- | `autoPlay` | `boolean?` | `false` | |
23
- | `speed` | `number?` | `100` | Milliseconds per frame |
24
- | `forwards` | `boolean?` | `true` | Direction |
15
+ | Field | Type | Default |
16
+ |---|---|---|
17
+ | `resource` | `string` | required SPRITE_ANIMATION name |
18
+ | `autoPlay` | `boolean?` | `true` |
19
+ | `speed` | `number?` | `100` ms/frame |
20
+ | `forwards` | `boolean?` | `false` |
25
21
 
26
- Methods: `play(times?)`, `stop()`, `gotoAndPlay(frame)`, `gotoAndStop(frame)`. Read-only getters: `currentFrame`, `totalFrames`. Events: `'complete'`, `'loop'`, `'frameChange'`.
22
+ Importing the package registers SPRITE_ANIMATION atlas parsing. The implementation parses **all** entries in JSON `frames` and plays the resulting frame-key order. It rewrites JSON `animations` keys but does not expose a clip selector and does not choose an animation by clip name. Use separate resources if distinct clips need independent playback.
27
23
 
28
- Side effect: importing this package registers `SPRITE_ANIMATION` resource handlers on the engine `resource` singleton.
24
+ Methods are `play(times?)`, `stop()`, `gotoAndPlay(frame)`, and `gotoAndStop(frame)`; getters are `currentFrame` and `totalFrames`. `play()`/`play(Infinity)` loops, `play(N > 0)` completes after N loops, and `play(0)` is a no-op. With finite playback, `forwards: true` stops on the last frame; otherwise it resets.
29
25
 
30
- ## Required setup
26
+ `play()` and `stop()` safely queue while the atlas loads. **`gotoAndPlay()` and `gotoAndStop()` do not queue and dereference the animation immediately, so calling them before async atlas readiness is unsafe.** Wait until the component has an animation/positive `totalFrames`.
31
27
 
32
- `RendererSystem` then `SpriteAnimationSystem`. Resource:
28
+ Events are `'loop'`, `'frameChange'`, and `'complete'` (no payload is forwarded). `'complete'` from the Component's finite-loop logic does not occur during infinite playback.
33
29
 
34
30
  ```ts
35
- import { RESOURCE_TYPE, resource } from '@combos-fun/engine';
36
-
37
- resource.addResource([{
38
- name: 'hero-run',
39
- type: RESOURCE_TYPE.SPRITE_ANIMATION,
40
- src: {
41
- image: { type: 'png', url: 'https://cdn.example/hero-run.png' },
42
- json: { type: 'json', url: 'https://cdn.example/hero-run.json' },
43
- },
44
- preload: true,
45
- }]);
31
+ hero.addComponent(new SpriteAnimation({
32
+ resource: 'hero-run',
33
+ autoPlay: true,
34
+ speed: 80,
35
+ }));
46
36
  ```
47
37
 
48
- JSON should be a Pixi spritesheet hash (`frames` name map + `meta.scale`).
49
-
50
- ## Common pitfalls
51
-
52
- | Symptom | Fix |
53
- |---------|-----|
54
- | Animation doesn't start | `autoPlay: false` is the default — call `play()` from a Component lifecycle hook, or set `autoPlay: true` |
55
- | Imperative `play()` from bootstrap | ECS violation — wire the call from a Component's `start()` |
56
- | `src.<slot>.url is required` | That slot has no url |
57
- | `SpriteAnimation resource load error` | Files loaded but no frames after parse |
58
- | Stuck on first frame | Frames may be a single image; check JSON has multiple **named** `frames` entries |
59
- | Animation never completes | `play(0)` (or omitted `times`) loops forever; pass a positive integer for finite plays |
60
- | `'complete'` doesn't fire | Only fires when `play(N)` finishes N iterations; not when looping forever |
61
-
62
- ## Minimal example
63
-
64
- ```ts
65
- const hero = new GameObject('hero', { position: { x: 200, y: 400 }, size: { width: 108, height: 108 }, origin: { x: 0.5, y: 0.5 } });
66
- hero.addComponent(new SpriteAnimation({ resource: 'hero-run', autoPlay: true, speed: 80 }));
67
- ```
68
-
69
- ## Verification
70
-
71
- `pnpm --filter @combos-fun/plugin-renderer-sprite-animation run build`.
38
+ Display width and height follow `Transform.size`, not frame pixels. Resource or speed changes are observed; `autoPlay` and `forwards` are not observer fields.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combos-fun/plugin-renderer-sprite-animation",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "description": "Frame-based sprite animation",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite-animation.esm.js",
@@ -37,10 +37,10 @@
37
37
  "author": "sun668 <q947692259@gmail.com>",
38
38
  "dependencies": {
39
39
  "pixi.js": "^8.18.1",
40
- "@combos-fun/renderer-adapter": "0.0.44",
41
- "@combos-fun/plugin-renderer": "0.0.44",
42
- "@combos-fun/inspector-decorator": "0.0.44",
43
- "@combos-fun/engine": "0.0.44"
40
+ "@combos-fun/engine": "0.0.46",
41
+ "@combos-fun/renderer-adapter": "0.0.46",
42
+ "@combos-fun/inspector-decorator": "0.0.46",
43
+ "@combos-fun/plugin-renderer": "0.0.46"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "node ../../scripts/build-package.mjs"