From 598fcc5cf42c025bd56f1452abd3fcbfa8b9eb2a Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Thu, 19 Dec 2024 18:06:32 +0100 Subject: [PATCH] WIP - Add interactivity events. isdraggable is currently broken. --- spine-ts/spine-core/src/Utils.ts | 4 +- .../example/webcomponent-tutorial.html | 101 +++++++ .../src/SpineWebComponentWidget.ts | 260 +++++++++++++++--- 3 files changed, 331 insertions(+), 34 deletions(-) diff --git a/spine-ts/spine-core/src/Utils.ts b/spine-ts/spine-core/src/Utils.ts index ddeb4f2c3..7048c5965 100644 --- a/spine-ts/spine-core/src/Utils.ts +++ b/spine-ts/spine-core/src/Utils.ts @@ -174,8 +174,8 @@ export class Color { return Number("0x" + hex(this.r) + hex(this.g) + hex(this.b)); } - static fromString (hex: string): Color { - return new Color().setFromString(hex); + static fromString (hex: string, color = new Color()): Color { + return color.setFromString(hex); } } diff --git a/spine-ts/spine-webgl/example/webcomponent-tutorial.html b/spine-ts/spine-webgl/example/webcomponent-tutorial.html index eaa42a264..d0bd8fa9a 100644 --- a/spine-ts/spine-webgl/example/webcomponent-tutorial.html +++ b/spine-ts/spine-webgl/example/webcomponent-tutorial.html @@ -2524,6 +2524,107 @@ const updateControl = (widget, controlBone, mouse, tempVector) => { (function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=global||self,global.Ola=factory())})(this,function(){"use strict";const position=(x0,v0,t1,t)=>{const a=(v0*t1+2*x0)/t1**3;const b=-(2*v0*t1+3*x0)/t1**2;const c=v0;const d=x0;return a*t**3+b*t**2+c*t+d};const speed=(x0,v0,t1,t)=>{const a=(v0*t1+2*x0)/t1**3;const b=-(2*v0*t1+3*x0)/t1**2;const c=v0;return 3*a*t**2+2*b*t+c};const each=function(values,cb){const multi=typeof values==="number"?{value:values}:values;Object.entries(multi).map(([key,value])=>cb(value,key))};function Single(init,time){this.start=new Date/1e3;this.time=time;this.from=init;this.current=init;this.to=init;this.speed=0}Single.prototype.get=function(now){const t=now/1e3-this.start;if(t<0){throw new Error("Cannot read in the past")}if(t>=this.time){return this.to}return this.to-position(this.to-this.from,this.speed,this.time,t)};Single.prototype.getSpeed=function(now){const t=now/1e3-this.start;if(t>=this.time){return 0}return speed(this.to-this.from,this.speed,this.time,t)};Single.prototype.set=function(value,time){const now=new Date;const current=this.get(now);this.speed=this.getSpeed(now);this.start=now/1e3;this.from=current;this.to=value;if(time){this.time=time}return current};function Ola(values,time=300){if(typeof values==="number"){values={value:values}}each(values,(init,key)=>{const value=new Single(init,time/1e3);Object.defineProperty(values,"_"+key,{value:value});Object.defineProperty(values,"$"+key,{get:()=>value.to});Object.defineProperty(values,key,{get:()=>value.get(new Date),set:val=>value.set(val),enumerable:true})});Object.defineProperty(values,"get",{get:()=>(function(name="value",now=new Date){return this["_"+name].get(now)})});Object.defineProperty(values,"set",{get:()=>(function(values,time=0){each(values,(value,key)=>{this["_"+key].set(value,time/1e3)})})});return values}return Ola}); + + + + +
+ +
+
+ You can attach callback to your widget to react at pointer interactions. Just make it isinteractive. +
+
+ You can attach a callback for interactions with the widget bounds or with slots. + The available events are down, up, enter, leave, move, and drag. +
+
+ In the following example, if the cursor enters the bounds, the jump animation is set, while the wave animation is set when the cursor leaves. +
+ If you click on the head-base slot (the face), you can change the normal and dark tint with the colors selected in the two following selectors. + +
    +
  • Tint normal:
  • +
  • Tint black:
  • +
+ +
+
+ + + +
+
+ +
+

+                
+            
+
+ +
+