Browse Source

RLottie change render flow (curFrame)

master
morethanwords 4 years ago
parent
commit
f4fa88308c
  1. 24
      src/lib/lottieLoader.ts

24
src/lib/lottieLoader.ts

@ -179,11 +179,13 @@ export class RLottiePlayer extends EventListenerBase<{
this.setMainLoop(); this.setMainLoop();
} }
public pause() { public pause(clearPendingRAF = true) {
if(this.paused) return; if(this.paused) return;
this.paused = true; this.paused = true;
if(clearPendingRAF) {
clearTimeout(this.rafId); clearTimeout(this.rafId);
}
//window.cancelAnimationFrame(this.rafId); //window.cancelAnimationFrame(this.rafId);
} }
@ -292,38 +294,34 @@ export class RLottiePlayer extends EventListenerBase<{
} }
private mainLoopForwards() { private mainLoopForwards() {
const frame = this.curFrame; const frame = this.curFrame >= this.frameCount ? this.curFrame = 0 : this.curFrame += this.skipDelta;
this.curFrame += this.skipDelta; //console.log('mainLoopForwards', this.curFrame, this.skipDelta, frame);
this.requestFrame(frame); this.requestFrame(frame);
if(this.curFrame >= this.frameCount) { if((frame + this.skipDelta) >= this.frameCount) {
//this.playedTimes++; //this.playedTimes++;
if(!this.loop) { if(!this.loop) {
this.pause(); this.pause(false);
return false; return false;
} }
this.curFrame = 0;
} }
return true; return true;
} }
private mainLoopBackwards() { private mainLoopBackwards() {
const frame = this.curFrame; const frame = this.curFrame < 0 ? this.curFrame = this.frameCount - 1 : this.curFrame -= this.skipDelta;
this.curFrame -= this.skipDelta; //console.log('mainLoopBackwards', this.curFrame, this.skipDelta, frame);
this.requestFrame(frame); this.requestFrame(frame);
if(this.curFrame < 0) { if((frame - this.skipDelta) < 0) {
//this.playedTimes++; //this.playedTimes++;
if(!this.loop) { if(!this.loop) {
this.pause(); this.pause(false);
return false; return false;
} }
this.curFrame = this.frameCount - 1;
} }
return true; return true;

Loading…
Cancel
Save