Add renderPaused property, closing #42

This commit is contained in:
yushijinhun 2019-12-27 19:04:32 +08:00
parent 1121ee4c09
commit b5593d1943
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
1 changed files with 28 additions and 11 deletions

View File

@ -40,6 +40,8 @@ export class SkinViewer {
public readonly playerObject: PlayerObject;
private _renderPaused: boolean = false;
constructor(options: SkinViewerOptions) {
this.domElement = options.domElement;
this.animation = options.animation || null;
@ -114,9 +116,13 @@ export class SkinViewer {
if (options.width) this.width = options.width;
if (options.height) this.height = options.height;
const draw = () => {
if (this.disposed) return;
window.requestAnimationFrame(draw);
window.requestAnimationFrame(() => this.draw());
}
private draw() {
if (this.disposed || this._renderPaused) {
return;
}
if (!this.animationPaused) {
this.animationTime++;
if (this.animation) {
@ -124,8 +130,7 @@ export class SkinViewer {
}
}
this.renderer.render(this.scene, this.camera);
};
draw();
window.requestAnimationFrame(() => this.draw());
}
setSize(width, height) {
@ -142,6 +147,18 @@ export class SkinViewer {
this.capeTexture.dispose();
}
get renderPaused() {
return this._renderPaused;
}
set renderPaused(value: boolean) {
const toResume = !this.disposed && !value && this._renderPaused;
this._renderPaused = value;
if (toResume) {
window.requestAnimationFrame(() => this.draw());
}
}
get skinUrl() {
return this.skinImg.src;
}