pixijs-dust 1.0.0 → 1.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1
4
+
5
+ - `spawn()` and `sequence()` take chains written in place as functions, chains created with `Animator.build()`, or both mixed.
6
+ - Removed `spawnInline()` and `sequenceInline()`: pass the functions to `spawn()` and `sequence()` instead.
7
+
3
8
  ## 1.0.0
4
9
 
5
10
  - Initial public version.
package/README.md CHANGED
@@ -105,9 +105,8 @@ Dust is driven by exactly one ticker. Attaching the same ticker again does nothi
105
105
  | `callback(fn)` | Calls `fn(target)` |
106
106
  | `callbackWithDelay(delay, fn)` | Waits, then calls `fn(target)` |
107
107
  | `custom(fn, duration)` | Calls `fn(progress)` on every frame, with progress from 0 to 1 |
108
- | `sequence(animator)` | Plays another chain as one action |
109
- | `spawn(...animators)` | Plays several chains at the same time as one action |
110
- | `sequenceInline(fn)` / `spawnInline(...fns)` | Same, with the nested chains written in place |
108
+ | `sequence(chain)` | Plays another chain as one action |
109
+ | `spawn(...chains)` | Plays several chains at the same time as one action |
111
110
  | `kill()` | Destroys the target; must be the last call of the chain |
112
111
 
113
112
  A duration that is omitted is `0`, the action applies its final value at once.
@@ -175,38 +174,43 @@ for (const sprite of sprites) {
175
174
 
176
175
  ## Parallel chains
177
176
 
178
- `spawn()` plays several chains at the same time as one action. The action ends when its longest chain ends, and the parent chain goes on:
177
+ `spawn()` plays several chains at the same time as one action. The action ends when its longest chain ends, and the parent chain goes on. Each chain is written in place, as a function that receives an empty chain to fill:
179
178
 
180
179
  ```ts
181
180
  Dust.animate(sprite)
182
181
  .spawn(
183
- Animator.build().moveTo(300, 200, 0.5),
184
- Animator.build().scaleTo(1.5, 0.3).scaleTo(1, 0.2),
185
- Animator.build().fadeIn(0.5),
182
+ anim => anim.moveTo(300, 200, 0.5),
183
+ anim => anim.scaleTo(1.5, 0.3).scaleTo(1, 0.2),
184
+ anim => anim.fadeIn(0.5),
185
+ )
186
+ .sequence(
187
+ blink => blink.fadeTo(0.2, 0.1).fadeTo(1, 0.1).repeat(3),
186
188
  )
187
- .delay(0.2)
188
189
  .kill();
189
190
  ```
190
191
 
191
- `spawnInline()` and `sequenceInline()` are the same with the nested chains written in place. Each function receives an empty chain to fill:
192
+ `spawn()` and `sequence()` also take chains created with `Animator.build()`, and both kinds can be mixed. Build the chain beforehand when you need the chain itself: to reuse it with `clone()`, or to pause, speed up or end one of the parallel chains:
192
193
 
193
194
  ```ts
194
- Dust.animate(sprite)
195
- .spawnInline(
196
- anim => anim.moveTo(300, 200, 0.5),
197
- anim => anim.scaleTo(1.5, 0.3).scaleTo(1, 0.2),
198
- )
199
- .sequenceInline(blink => blink.fadeTo(0.2, 0.1).fadeTo(1, 0.1).repeat(3));
200
- ```
195
+ const move = Animator.build().moveTo(300, 200, 0.5);
201
196
 
202
- Use the first form when you need the chain itself: to reuse it with `clone()`, or to pause, speed up or end one of the parallel chains.
197
+ Dust.animate(sprite).spawn(
198
+ move,
199
+ anim => anim.fadeIn(0.5),
200
+ );
201
+ ```
203
202
 
204
203
  A chain that repeats forever holds its `spawn()` or `sequence()` until you end it with `complete()`:
205
204
 
206
205
  ```ts
207
206
  const pulse = Animator.build().scaleTo(1.2, 0.3).scaleTo(1, 0.3).forever();
208
207
 
209
- Dust.animate(sprite).spawn(pulse, Animator.build().moveTo(300, 200, 2)).fadeOut(0.3);
208
+ Dust.animate(sprite)
209
+ .spawn(
210
+ pulse,
211
+ anim => anim.moveTo(300, 200, 2),
212
+ )
213
+ .fadeOut(0.3);
210
214
 
211
215
  pulse.complete(); // the pulse ends after its current loop, then the sprite fades out
212
216
  ```
package/dist/index.cjs CHANGED
@@ -112,7 +112,9 @@ var Animator = class _Animator {
112
112
  this._name = name;
113
113
  }
114
114
  /**
115
- * Creates a chain without a target, to be played inside another chain with {@link Animator.sequence}.
115
+ * Creates a chain without a target, to be played inside another chain with {@link Animator.sequence}
116
+ * or {@link Animator.spawn}. Use it when the chain itself is needed: to reuse it with {@link Animator.clone},
117
+ * or to control it while it plays.
116
118
  *
117
119
  * @example
118
120
  * const blink = Animator.build().fadeTo(0.2, 0.1).fadeTo(1, 0.1).repeat(3);
@@ -122,10 +124,13 @@ var Animator = class _Animator {
122
124
  static build() {
123
125
  return new _Animator();
124
126
  }
125
- // Creates a chain without a target and lets the function fill it
126
- static buildWith(builder) {
127
+ // Returns the chain as is, or creates a chain without a target and lets the function fill it
128
+ static resolveNested(nested) {
129
+ if (nested instanceof _Animator) {
130
+ return nested;
131
+ }
127
132
  const chain = _Animator.build();
128
- builder(chain);
133
+ nested(chain);
129
134
  return chain;
130
135
  }
131
136
  /**
@@ -438,59 +443,43 @@ var Animator = class _Animator {
438
443
  /**
439
444
  * Plays another chain as one action of this chain, with its own repeat count.
440
445
  *
441
- * A chain can belong to one animation only: pass `animator.clone()` to use it in several places.
446
+ * The chain is either written in place, as a function that receives an empty chain and adds actions to it,
447
+ * or created beforehand with {@link Animator.build}. A chain can belong to one animation only:
448
+ * pass `animator.clone()` to use it in several places.
442
449
  *
443
- * @param animator - A chain created with {@link Animator.build}.
444
- * @throws When the chain is already used in a sequence.
445
- */
446
- sequence(animator) {
447
- return this.push(new Sequence(animator));
448
- }
449
- /**
450
- * Same as {@link Animator.sequence}, with the nested chain written in place.
451
- * The function receives an empty chain and adds actions to it.
450
+ * @param chain - A function that fills the nested chain, or a chain created with {@link Animator.build}.
451
+ * @throws When the chain is already used as a nested chain.
452
452
  *
453
453
  * @example
454
- * Dust.animate(sprite).sequenceInline(blink => blink.fadeTo(0.2, 0.1).fadeTo(1, 0.1).repeat(3));
454
+ * Dust.animate(sprite).sequence(
455
+ * blink => blink.fadeTo(0.2, 0.1).fadeTo(1, 0.1).repeat(3),
456
+ * );
455
457
  */
456
- sequenceInline(builder) {
457
- return this.sequence(_Animator.buildWith(builder));
458
+ sequence(chain) {
459
+ return this.push(new Sequence(_Animator.resolveNested(chain)));
458
460
  }
459
461
  /**
460
462
  * Plays several chains at the same time as one action of this chain.
461
463
  * The action ends when its longest chain ends; a chain that repeats forever holds it until
462
464
  * that chain is ended with {@link Animator.complete}.
463
465
  *
464
- * A chain can belong to one animation only: pass `animator.clone()` to use it in several places.
466
+ * Every chain is either written in place, as a function that receives an empty chain and adds actions to it,
467
+ * or created beforehand with {@link Animator.build}; both kinds can be mixed. A chain can belong to one
468
+ * animation only: pass `animator.clone()` to use it in several places.
465
469
  *
466
- * @param animators - Chains created with {@link Animator.build}.
470
+ * @param chains - Functions that fill the nested chains, or chains created with {@link Animator.build}.
467
471
  * @throws When one of the chains is already used as a nested chain.
468
472
  *
469
473
  * @example
470
474
  * Dust.animate(sprite)
471
475
  * .spawn(
472
- * Animator.build().moveTo(300, 200, 0.5),
473
- * Animator.build().scaleTo(1.5, 0.3).scaleTo(1, 0.2),
474
- * )
475
- * .fadeOut(0.3);
476
- */
477
- spawn(...animators) {
478
- return this.push(new Spawn(animators));
479
- }
480
- /**
481
- * Same as {@link Animator.spawn}, with the chains written in place.
482
- * Every function receives an empty chain and adds actions to it.
483
- *
484
- * @example
485
- * Dust.animate(sprite)
486
- * .spawnInline(
487
476
  * anim => anim.moveTo(300, 200, 0.5),
488
477
  * anim => anim.scaleTo(1.5, 0.3).scaleTo(1, 0.2),
489
478
  * )
490
479
  * .fadeOut(0.3);
491
480
  */
492
- spawnInline(...builders) {
493
- return this.spawn(...builders.map((builder) => _Animator.buildWith(builder)));
481
+ spawn(...chains) {
482
+ return this.push(new Spawn(chains.map((chain) => _Animator.resolveNested(chain))));
494
483
  }
495
484
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
496
485
  /**