Skip to content

Commit

Permalink
Made span fps display configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidetan committed Sep 26, 2024
1 parent a254fab commit 27edd8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spine-ts/spine-webgl/example/webcomponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,9 @@
/////////////////////
-->

<script>
spine.SpineWebComponentWidget.SHOW_FPS = true;
</script>


<script>
Expand Down
24 changes: 21 additions & 3 deletions spine-ts/spine-webgl/src/SpineWebComponentWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ interface WidgetInternalProperties {
debugDragDiv: HTMLDivElement
}

class SpineWebComponentWidget extends HTMLElement implements WidgetAttributes, WidgetOverridableMethods, WidgetInternalProperties, Partial<WidgetPublicProperties> {
export class SpineWebComponentWidget extends HTMLElement implements WidgetAttributes, WidgetOverridableMethods, WidgetInternalProperties, Partial<WidgetPublicProperties> {

/**
* If true, enables a top-left span showing FPS (it has black text)
*/
public static SHOW_FPS = false;

/**
* The URL of the skeleton atlas file (.atlas)
Expand Down Expand Up @@ -833,6 +838,7 @@ class SpineWebComponentOverlay extends HTMLElement {
private div: HTMLDivElement;
private canvas:HTMLCanvasElement;
private fps: HTMLSpanElement;
private fpsAppended = false;

public skeletonList = new Array<SpineWebComponentWidget>();

Expand Down Expand Up @@ -886,7 +892,6 @@ class SpineWebComponentOverlay extends HTMLElement {
this.fps.style.position = "fixed";
this.fps.style.top = "0";
this.fps.style.left = "0";
this.root.appendChild(this.fps);

const context = new ManagedWebGLRenderingContext(this.canvas, { alpha: true });
this.renderer = new SceneRenderer(this.canvas, context);
Expand Down Expand Up @@ -950,7 +955,20 @@ class SpineWebComponentOverlay extends HTMLElement {
}
}
});
this.fps.innerText = this.time.framesPerSecond.toFixed(2) + " fps";

// fps top-left span
if (SpineWebComponentWidget.SHOW_FPS) {
if (!this.fpsAppended) {
this.root.appendChild(this.fps);
this.fpsAppended = true;
}
this.fps.innerText = this.time.framesPerSecond.toFixed(2) + " fps";
} else {
if (this.fpsAppended) {
this.root.removeChild(this.fps);
this.fpsAppended = false;
}
}
};

const clear = (r: number, g: number, b: number, a: number) => {
Expand Down

0 comments on commit 27edd8a

Please sign in to comment.