Skip to content

Commit

Permalink
Fix #14992 (#14994)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh committed Apr 16, 2024
1 parent 3fdd140 commit c9644ea
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/dev/core/src/Animations/runtimeAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export class RuntimeAnimation {
*/
private _previousElapsedTime: number = 0;

private _yoyoDirection: number = 1;

/**
* The previous absolute frame of the runtime animation (meaning, without taking into account the from/to values, only the elapsed time and the fps)
*/
Expand Down Expand Up @@ -512,14 +514,24 @@ export class RuntimeAnimation {
let highLimitValue = 0;

// Apply the yoyo function if required
if (loop && this._animationState.loopMode === Animation.ANIMATIONLOOPMODE_YOYO) {
let yoyoLoop = false;
const yoyoMode = loop && this._animationState.loopMode === Animation.ANIMATIONLOOPMODE_YOYO;
if (yoyoMode) {
const position = (absoluteFrame - from) / frameRange;

// Apply the yoyo curve
const yoyoPosition = Math.abs(Math.sin(position * Math.PI));
const sin = Math.sin(position * Math.PI);
const yoyoPosition = Math.abs(sin);

// Map the yoyo position back to the range
absoluteFrame = yoyoPosition * frameRange + from;

const direction = sin >= 0 ? 1 : -1;
if (this._yoyoDirection !== direction) {
yoyoLoop = true;
}

this._yoyoDirection = direction;
}

this._previousElapsedTime = elapsedTimeSinceAnimationStart;
Expand Down Expand Up @@ -628,7 +640,7 @@ export class RuntimeAnimation {
const events = this._events;

// Reset event/state if looping
if ((speedRatio > 0 && this.currentFrame > currentFrame) || (speedRatio < 0 && this.currentFrame < currentFrame)) {
if ((!yoyoMode && ((speedRatio > 0 && this.currentFrame > currentFrame) || (speedRatio < 0 && this.currentFrame < currentFrame))) || (yoyoMode && yoyoLoop)) {
this._onLoop();

// Need to reset animation events
Expand Down

0 comments on commit c9644ea

Please sign in to comment.