Skip to content

Commit

Permalink
Fix gotoAndStop issue
Browse files Browse the repository at this point in the history
Fix issue with jumping to a non-keyframed frame following a tween
  • Loading branch information
ericente authored and andrewstart committed Jan 9, 2023
1 parent 18ab976 commit 4f2879e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/animate/Timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export class Timeline extends Array<Tween>
* @method PIXI.animate.Timeline#addKeyframe
* @param {Object} properties The properties to set.
* @param {int} startFrame The starting frame index.
* @param {int} [duration = 0] The number of frames to hold beyond startFrame (0 is single frame)
*/
public addKeyframe(properties: TweenProps, startFrame: number): void
public addKeyframe(properties: TweenProps, startFrame: number, duration = 0): void
{
// see if we need to go back in and insert properties
if (this.length && this[this.length - 1].startFrame >= startFrame)
Expand Down Expand Up @@ -130,7 +131,7 @@ export class Timeline extends Array<Tween>
prev.endFrame = startFrame - 1;
const startProps = Object.assign({}, prev.endProps, properties);
// create the new Tween and add it to the list
const tween = new Tween(this.target, startProps, null, startFrame, 0);
const tween = new Tween(this.target, startProps, null, startFrame, duration);

this.splice(i, 0, tween);
// go through any later keyframes to update them with our inserted props
Expand All @@ -148,7 +149,7 @@ export class Timeline extends Array<Tween>
{
const startProps = Object.assign({}, prev.endProps, properties);
// create the new Tween and add it to the list
const tween = new Tween(this.target, startProps, null, startFrame, 0);
const tween = new Tween(this.target, startProps, null, startFrame, duration);

this.splice(i, 0, tween);

Expand All @@ -171,7 +172,7 @@ export class Timeline extends Array<Tween>
this.extendLastFrame(startFrame - 1);
const startProps = Object.assign({}, this._currentProps, properties);
// create the new Tween and add it to the list
const tween = new Tween(this.target, startProps, null, startFrame, 0);
const tween = new Tween(this.target, startProps, null, startFrame, duration);

this.push(tween);
Object.assign(this._currentProps, tween.endProps);
Expand All @@ -194,13 +195,14 @@ export class Timeline extends Array<Tween>
if (prevTween.isTweenlessFrame)
{
prevTween.endFrame = endFrame;
prevTween.duration = endFrame - prevTween.startFrame;
}
else
{
this.addKeyframe(
this._currentProps,
prevTween.endFrame + 1,
// endFrame - prevTween.endFrame + 1
endFrame - (prevTween.endFrame + 1),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/animate/Tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class Tween
*/
public endProps: TweenProps;
/**
* duration of tween in frames. For a keyframe with no tweening, the duration will be 0.
* duration of tween in frames. A single-frame keyframe has a duration of 0.
*/
public duration: number;
/**
Expand Down

0 comments on commit 4f2879e

Please sign in to comment.