UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

63 lines (62 loc) 1.86 kB
import easingFuncs from "./easing.mjs"; import { noop, isFunction } from "../core/util.mjs"; import { createCubicEasingFunc } from "./cubicEasing.mjs"; var Clip = function() { function Clip2(opts) { this._inited = false; this._startTime = 0; this._pausedTime = 0; this._paused = false; this._life = opts.life || 1e3; this._delay = opts.delay || 0; this.loop = opts.loop || false; this.onframe = opts.onframe || noop; this.ondestroy = opts.ondestroy || noop; this.onrestart = opts.onrestart || noop; opts.easing && this.setEasing(opts.easing); } Clip2.prototype.step = function(globalTime, deltaTime) { if (!this._inited) { this._startTime = globalTime + this._delay; this._inited = true; } if (this._paused) { this._pausedTime += deltaTime; return; } var life = this._life; var elapsedTime = globalTime - this._startTime - this._pausedTime; var percent = elapsedTime / life; if (percent < 0) { percent = 0; } percent = Math.min(percent, 1); var easingFunc = this.easingFunc; var schedule = easingFunc ? easingFunc(percent) : percent; this.onframe(schedule); if (percent === 1) { if (this.loop) { var remainder = elapsedTime % life; this._startTime = globalTime - remainder; this._pausedTime = 0; this.onrestart(); } else { return true; } } return false; }; Clip2.prototype.pause = function() { this._paused = true; }; Clip2.prototype.resume = function() { this._paused = false; }; Clip2.prototype.setEasing = function(easing) { this.easing = easing; this.easingFunc = isFunction(easing) ? easing : easingFuncs[easing] || createCubicEasingFunc(easing); }; return Clip2; }(); var Clip$1 = Clip; export { Clip$1 as default };