UNPKG

@mint-ui/map

Version:

- React map library - Control various map with one interface - Google, Naver, Kakao map supported now - Typescript supported - Canvas marker supported

80 lines (60 loc) 1.85 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var AnimationPlayer = /** @class */ function () { function AnimationPlayer(drawFunction, fps) { this.prevtime = 0; this.elapsedTime = 0; this.fps = null; this.baseDrawGapTime = null; this.deltaTime = 0; this.playing = false; this.draw = drawFunction; this.fps = fps || null; if (fps !== undefined) { this.baseDrawGapTime = 1000 / fps; } this.init(); } AnimationPlayer.prototype.init = function () { this.deltaTime = 0; this.prevtime = 0; this.elapsedTime = 0; this.playing = false; }; AnimationPlayer.prototype.start = function () { this.init(); this.resume(); }; AnimationPlayer.prototype.stop = function () { this.playing = false; }; AnimationPlayer.prototype.resume = function () { this.playing = true; //@ts-ignore window.requestAnimationFrame(this.makeFrame.bind(this)); }; AnimationPlayer.prototype.makeFrame = function (timestamp) { //frame 간 시간 변화 if (this.prevtime === 0) { this.prevtime = timestamp; } this.deltaTime += timestamp - this.prevtime; //정해진 시간이 없거나, 정해진 시간이 지났으면 draw 호출 this.prevtime = timestamp; if (!this.baseDrawGapTime || this.baseDrawGapTime <= this.deltaTime) { //다음 루프 준비 this.elapsedTime += this.deltaTime; //draw 콜백에서 stop 신호오면 멈춤 var stopFlag = this.draw(this.deltaTime, this.elapsedTime); //delta 초기화 this.deltaTime = 0; if (stopFlag) { this.stop(); } } if (this.playing) { //@ts-ignore window.requestAnimationFrame(this.makeFrame.bind(this)); } }; return AnimationPlayer; }(); exports.AnimationPlayer = AnimationPlayer;