diff --git a/packages/f-engine/src/canvas/timeline.ts b/packages/f-engine/src/canvas/timeline.ts index ae9cace..9bed94e 100644 --- a/packages/f-engine/src/canvas/timeline.ts +++ b/packages/f-engine/src/canvas/timeline.ts @@ -119,22 +119,28 @@ class Timeline extends EE { const { frame, animUnits, playState } = this; let target; - for (let i = 0; i < animUnits.length; i++) { - const cur = animUnits[i]; - target = i; - if (time > cur.time) { + for (target = 0; target < animUnits.length; target++) { + const cur = animUnits[target]; + if (time >= cur.time) { time -= cur.time; // 计算剩余时间 } else { break; } } + // 超出了总时长 + if (target === animUnits.length && time > 0) { + this.setPlayState('finish'); + return; + } + if (frame !== target) { this.frame = target; this.drawFrame(); this.animator.run(); this.setPlayState(playState); } + this.animator.goTo(time); } } diff --git "a/packages/f-engine/test/timeline/__image_snapshots__/player-test-tsx-clip-animation-\350\267\263\350\275\254\350\266\205\345\207\272\346\200\273\346\227\266\351\225\277-1-snap.png" "b/packages/f-engine/test/timeline/__image_snapshots__/player-test-tsx-clip-animation-\350\267\263\350\275\254\350\266\205\345\207\272\346\200\273\346\227\266\351\225\277-1-snap.png" new file mode 100644 index 0000000..863f60f Binary files /dev/null and "b/packages/f-engine/test/timeline/__image_snapshots__/player-test-tsx-clip-animation-\350\267\263\350\275\254\350\266\205\345\207\272\346\200\273\346\227\266\351\225\277-1-snap.png" differ diff --git a/packages/f-engine/test/timeline/player.test.tsx b/packages/f-engine/test/timeline/player.test.tsx index be86ca0..a9e2d6e 100644 --- a/packages/f-engine/test/timeline/player.test.tsx +++ b/packages/f-engine/test/timeline/player.test.tsx @@ -372,4 +372,58 @@ describe('clip animation', () => { expect(context).toMatchImageSnapshot(); }); + + it('跳转超出总时长', async () => { + const context = createContext('跳转超出总时长'); + + //结束后重播 + const { props } = ( + + + + + + ); + + const canvas = new Canvas(props); + await canvas.render(); + await delay(100); + + const { props: newProps } = ( + + + + + + ); + + await canvas.update(newProps); + await delay(100); + expect(context).toMatchImageSnapshot(); + }); });