Skip to content

Commit

Permalink
Translate is done each frame through requestAnimationFrame.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidetan committed Sep 19, 2024
1 parent 2716b4d commit 673ee9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spine-ts/spine-webgl/src/SpineWebComponentWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ class SpineWebComponentOverlay extends HTMLElement {

this.updateCanvasSize();
this.zoomHandler();

// translateCanvas starts a requestAnimationFrame loop
this.translateCanvas();

this.overflowLeftSize = this.overflowLeft * document.documentElement.clientWidth;
Expand Down Expand Up @@ -955,14 +957,17 @@ class SpineWebComponentOverlay extends HTMLElement {
}
}

// right now, we scroll the canvas each frame, that makes scrolling on mobile waaay more smoother
// this is way scroll handler do nothing
private scrollHandler = () => {
this.translateCanvas();
// this.translateCanvas();
}

private translateCanvas() {
const scrollPositionX = window.scrollX - this.overflowLeftSize;
const scrollPositionY = window.scrollY - this.overflowTopSize;
this.canvas.style.transform =`translate(${scrollPositionX}px,${scrollPositionY}px)`;
requestAnimationFrame(() => this.translateCanvas());
}

private zoomHandler = () => {
Expand Down

0 comments on commit 673ee9e

Please sign in to comment.