@tawaship/pixi-animate-runtime 0.1.0 → 0.1.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @tawaship/pixi-animate-runtime - v0.1.0
2
+ * @tawaship/pixi-animate-runtime - v0.1.1
3
3
  *
4
4
  * @author tawaship (makazu.mori@gmail.com)
5
5
  * @license MIT
@@ -425,6 +425,12 @@ var DisplayObject = /*@__PURE__*/(function (EventDispatcher) {
425
425
  this._maskHost = null;
426
426
  /** The objects this object masks (while they are on a display list) */
427
427
  this._maskTargets = [];
428
+ /**
429
+ * Set on a root when a timeline under it jumped outside the playing (a goto):
430
+ * its clips are to be settled before Pixi draws it (settleForDrawing), as a
431
+ * createjs draw would. The resolve phase of a frame clears it
432
+ */
433
+ this._pendingResolve = false;
428
434
  this.id = nextId++;
429
435
  this.pixi = pixi;
430
436
  pixi.owner = this;
@@ -1219,6 +1225,13 @@ var MovieClip = /*@__PURE__*/(function (Container) {
1219
1225
  if (position != null) {
1220
1226
  this._t = 0;
1221
1227
  this._updateTimeline(position, true);
1228
+ // The clips it placed (synched ones, ones to start over) are settled by createjs when it
1229
+ // draws: the root is to be settled before Pixi draws it, if no frame is played before
1230
+ var root = this;
1231
+ while (root.parent) {
1232
+ root = root.parent;
1233
+ }
1234
+ root._pendingResolve = true;
1222
1235
  }
1223
1236
  };
1224
1237
  MovieClip.prototype._reset = function _reset () {
@@ -2663,7 +2676,7 @@ function checkVersion(version, range, known) {
2663
2676
  }
2664
2677
 
2665
2678
  /** The version of this package (written in from package.json when the package is built) */
2666
- var VERSION = "0.1.0";
2679
+ var VERSION = "0.1.1";
2667
2680
 
2668
2681
  /**
2669
2682
  * The eases of CreateJS (createjs.Ease), computed as CreateJS computes them,
@@ -3310,6 +3323,7 @@ function tick(root, event) {
3310
3323
  * reverse order), without playing a frame.
3311
3324
  */
3312
3325
  function resolveState(node) {
3326
+ node._pendingResolve = false;
3313
3327
  if (node instanceof MovieClip) {
3314
3328
  node._updateState();
3315
3329
  }
@@ -3322,6 +3336,34 @@ function resolveState(node) {
3322
3336
  }
3323
3337
  }
3324
3338
  }
3339
+ /**
3340
+ * Settles a display tree for drawing without playing it on, as a createjs
3341
+ * stage draw shows it (MovieClip.draw settles each clip): the synched and
3342
+ * single frame clips are placed at the frame their parent gives, and a clip
3343
+ * waiting to start over (an independent clip reset when its parent placed it
3344
+ * again) is shown at its first frame the way a new clip is (no frame script,
3345
+ * its playhead left to start on the next frame, as in the template, where
3346
+ * createjs draws only after a frame). Children after their parent, in reverse
3347
+ * order as the resolve phase.
3348
+ */
3349
+ function settleForDrawing(node) {
3350
+ if (node instanceof MovieClip) {
3351
+ if (node.mode !== INDEPENDENT) {
3352
+ node._updateState();
3353
+ }
3354
+ else if (node._rawPosition === -1) {
3355
+ node._renderFirstFrame();
3356
+ }
3357
+ }
3358
+ if (node instanceof Container) {
3359
+ var children = node.children.slice();
3360
+ for (var i = children.length - 1; i >= 0; i--) {
3361
+ if (children[i] instanceof MovieClip) {
3362
+ settleForDrawing(children[i]);
3363
+ }
3364
+ }
3365
+ }
3366
+ }
3325
3367
 
3326
3368
  /** The frame rate a root plays at when its content does not give one */
3327
3369
  var DEFAULT_FPS = 60;
@@ -3347,7 +3389,7 @@ var PULL = 0.05;
3347
3389
  * on only settles it on its first frame.
3348
3390
  */
3349
3391
  var AnimateController = function AnimateController(container) {
3350
- /** Playback speed (1 is the content's own frame rate) */
3392
+ /** Playback speed (1 is the content's own frame rate, 0 stops; a value below 0 is taken as 0) */
3351
3393
  this.speed = 1;
3352
3394
  /** Whether one call may play more than one frame (when the display runs slower than the content) */
3353
3395
  this.overSpeed = true;
@@ -3359,12 +3401,34 @@ var AnimateController = function AnimateController(container) {
3359
3401
  this._deltas = [];
3360
3402
  this._nextDelta = 0;
3361
3403
  this._container = container;
3404
+ // Pixi updates the transforms of the tree before every draw: the roots a goto changed outside
3405
+ // the playing are settled then, as a createjs draw settles them (frames played meanwhile settle them first)
3406
+ var updateTransform = container.updateTransform;
3407
+ var controller = this;
3408
+ container.updateTransform = function () {
3409
+ controller._settleForDrawing();
3410
+ updateTransform.call(this);
3411
+ };
3412
+ };
3413
+ /** Settles the roots marked by a goto since they were last resolved */
3414
+ AnimateController.prototype._settleForDrawing = function _settleForDrawing () {
3415
+ var targets = this._targets;
3416
+ Object.keys(targets).forEach(function (key) {
3417
+ var target = targets[Number(key)];
3418
+ if (target && target.root._pendingResolve) {
3419
+ target.root._pendingResolve = false;
3420
+ settleForDrawing(target.root);
3421
+ }
3422
+ });
3362
3423
  };
3363
3424
  AnimateController.prototype.handleTick = function handleTick (delta) {
3364
3425
  var this$1$1 = this;
3365
3426
 
3366
- var d = delta * this.speed;
3367
- var usual = this._usualDelta(delta) * this.speed;
3427
+ // A speed below 0 plays as 0 does (nothing is played backward): the frames owed stay where they
3428
+ // were, and the playing goes on from there once the speed is above 0 again
3429
+ var speed = Math.max(this.speed, 0);
3430
+ var d = delta * speed;
3431
+ var usual = this._usualDelta(delta) * speed;
3368
3432
  var targets = this._targets;
3369
3433
  Object.keys(targets).forEach(function (key) {
3370
3434
  var target = targets[Number(key)];
@@ -3470,7 +3534,7 @@ var AnimateContainer = /*@__PURE__*/(function (superclass) {
3470
3534
  AnimateContainer.prototype.constructor = AnimateContainer;
3471
3535
 
3472
3536
  var prototypeAccessors = { speed: { configurable: true },overSpeed: { configurable: true },smooth: { configurable: true } };
3473
- /** Playback speed (1 is the content's own frame rate) */
3537
+ /** Playback speed (1 is the content's own frame rate, 0 stops; a value below 0 is taken as 0) */
3474
3538
  prototypeAccessors.speed.get = function () { return this._controller.speed; };
3475
3539
  prototypeAccessors.speed.set = function (value) { this._controller.speed = value; };
3476
3540
  /** Whether one call may play more than one frame (when the display runs slower than the content) */