From 4d795da488bf2251f01288c81f964bed329c0f78 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Fri, 20 Dec 2024 15:18:10 +0100 Subject: [PATCH] Add interactivity events. --- .../example/webcomponent-tutorial.html | 292 ++++++++++-------- .../src/SpineWebComponentWidget.ts | 71 +++-- 2 files changed, 199 insertions(+), 164 deletions(-) diff --git a/spine-ts/spine-webgl/example/webcomponent-tutorial.html b/spine-ts/spine-webgl/example/webcomponent-tutorial.html index d0bd8fa9a..6b0796ea1 100644 --- a/spine-ts/spine-webgl/example/webcomponent-tutorial.html +++ b/spine-ts/spine-webgl/example/webcomponent-tutorial.html @@ -2378,13 +2378,14 @@ function createCircleOfDivs(numDivs = 8) { customElements.whenDefined('spine-widget').then(async () => { const widget = spine.getSpineWidget(\`owl\${i}\`); await widget.loadingPromise; - widget.state.setAnimation(1, "blink", true) + widget.state.setAnimation(1, "blink", true); const control = widget.skeleton.findBone("control"); const tempVector = new spine.Vector3(); - const mouse = Ola({ x: 0, y: 0 }, 200); + const mouseX = Smooth(0, 200); + const mouseY = Smooth(0, 200); widget.afterUpdateWorldTransforms = () => { - updateControl(widget, control, mouse, tempVector); + updateControl(widget, control, mouseX, mouseY, tempVector); } }); @@ -2401,7 +2402,7 @@ const checkbox = document.getElementById('owl-checkbox'); let limitOwl = true; checkbox.addEventListener('change', () => limitOwl = checkbox.checked); -const updateControl = (widget, controlBone, mouse, tempVector) => { +const updateControl = (widget, controlBone, mouseX, mouseY, tempVector) => { controlBone.parent.worldToLocal(tempVector.set( widget.cursorWorldX, widget.cursorWorldY, @@ -2415,10 +2416,8 @@ const updateControl = (widget, controlBone, mouse, tempVector) => { y = y / widget.overlay.canvas.height * 30; } - mouse.set({ x, y }); - - controlBone.x = controlBone.data.x + mouse.x; - controlBone.y = controlBone.data.y + mouse.y; + controlBone.x = controlBone.data.x + mouseX(x); + controlBone.y = controlBone.data.y + mouseY(y); } ` ); @@ -2429,99 +2428,98 @@ const updateControl = (widget, controlBone, mouse, tempVector) => {