From fb3ebb56eba4ac8ccfb782f9e2103fa5eae4d1db Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Apr 2023 15:41:54 +0200 Subject: [PATCH] [phaser] More tests, fix make factory, add Alpha mixin --- .../spine-phaser/example/assets/phaser.png | Bin 0 -> 5507 bytes .../spine-phaser/example/basic-example.html | 2 +- .../spine-phaser/example/canvas-test.html | 44 ++++++++ spine-ts/spine-phaser/example/depth-test.html | 48 ++++++++ .../example/extended-class-test.html | 103 ++++++++++++++++++ spine-ts/spine-phaser/example/index.html | 4 + .../example/render-to-texture-test.html | 58 ++++++++++ spine-ts/spine-phaser/src/SpineGameObject.ts | 7 +- spine-ts/spine-phaser/src/SpinePlugin.ts | 7 +- spine-ts/spine-phaser/src/mixins.ts | 3 + 10 files changed, 269 insertions(+), 7 deletions(-) create mode 100644 spine-ts/spine-phaser/example/assets/phaser.png create mode 100644 spine-ts/spine-phaser/example/canvas-test.html create mode 100644 spine-ts/spine-phaser/example/depth-test.html create mode 100644 spine-ts/spine-phaser/example/extended-class-test.html create mode 100644 spine-ts/spine-phaser/example/render-to-texture-test.html diff --git a/spine-ts/spine-phaser/example/assets/phaser.png b/spine-ts/spine-phaser/example/assets/phaser.png new file mode 100644 index 0000000000000000000000000000000000000000..c824db910e96a6c61776e49411722ac4ca999f3d GIT binary patch literal 5507 zcmV-}6@2Q6P)@B#>5nXm_={vokyQbbjCKem$>yW~E)oKPmL!ZTEEdyT12(zwdZYej+l- zPC|$=^H}ezJy)qzDv@cLTu-1sir1w*3{HceSJOgRrP_##EHknc|6Z_S#aXK>ggQGrX>f25?FOBGaD9!9jda2Zv#F`6nZn_a zte1t&f*%+dpk2FmQCC+N<|03!j{#+u0({duIyz|Hym{2x+9KQMvQ`}eeacZ^Umv~q z-g~rX&+ZNgW+~c#Nv|gu3{rc0JDqdRIr7SY=02-QQUb01j3=|CJu5li@$XC~3-AtM z97iY~k4xDEg8^B_s;ekL!Qb+49<#SStFDs$%#@2Ml}gg+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!DO|;+EFL4wsqc3C13sG45|$I9CpMl_MYAd*pW5gE z=n1oYpjRH*_}%7>wy-Ug$ZQ)A!TWRX&{r^y9(m?whcl*BeI+ec!(FTg^Z2Vsm%Y9I zMBdp`y;2G7%*9-)(4 zBNZs?9nMQNrg^-p#|@w~tjmLY;b|30M>{SwzF2`#IfyK5gpuL=xY#EG&#bK_M1G&! zyHG}N%A;mjMX>k9S=o!)>rHa+4)69Lv#Rq$W7dYOBe#4`Xo0FP2zxxZC?W!0JmI1N-!QBnxfYNR!~}*M$tn z7*tyu*RNUYS~faa0{b+SHJ#I%Jozlh2&ktXU^kp?i84;uDD5ADjajVJCr+4xOy{VG zI!2;gcgc{jM_XIN@@%xw90qwb1u`8O$yH@=F}9vz02TKC&n{_Dw>O4dIFqLqp(Zc; zvLlPLpvF!g(}?E82dIa_GY-4zDs(d6Pn=Q(igc{&k)1qS<(Ypup zU?0Op#0o^y@cg;A{+mvJ^lJeT)ubGDRb$~KX0$PO1HoN zJ}o};bZO(b1B4cnkZyDF2|u58sI07ROy{1@O>>;5d_LMLJf|@LBRXF`YFaAWW8Nbh zeBfQ00cNE--~(wX`>@h{7|L>kS|>T}RN^_d5v}A6S+GjKddc!H(Vh2iptoU6D?^&E zbrB!Mi+yz6veVQ*Rk{bp^xstgXgukY0%)RjPo&&9(s`)+KRx|gptI6vF=+r=hRgH( zPq#L`_&yDZ$&`==dD;700MLE&FR!9)uf51Wk07@JMA->PqW>SJ17iT?ZRCS=JaPIX z^3GzhAh$Q>==)=K8iJRp8Pko-Sk7WJP4l=2Kf{UlHeuJ?irb&nH%y`}f7(SmdW&)+ zTS0^O%T8_e(UptmP-0jflzSEobm?b-fsUu~rC;-o%Fy5dy|8sN&2A1mdz$i}XYoHg z429{EE1V + + + + + + + + Spine Phaser Example + + +

Canvas test

+ + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/depth-test.html b/spine-ts/spine-phaser/example/depth-test.html new file mode 100644 index 000000000..4182b26b1 --- /dev/null +++ b/spine-ts/spine-phaser/example/depth-test.html @@ -0,0 +1,48 @@ + + + + + + + + + Spine Phaser Example + + +

Depth test

+ + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/extended-class-test.html b/spine-ts/spine-phaser/example/extended-class-test.html new file mode 100644 index 000000000..8760d5ba2 --- /dev/null +++ b/spine-ts/spine-phaser/example/extended-class-test.html @@ -0,0 +1,103 @@ + + + + + + + + + + Spine Phaser Example + + + +

Extended class

+ + + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/index.html b/spine-ts/spine-phaser/example/index.html index 99bbf7a67..72d76b56f 100644 --- a/spine-ts/spine-phaser/example/index.html +++ b/spine-ts/spine-phaser/example/index.html @@ -19,6 +19,10 @@
  • Blend test
  • Camera pipeline test
  • Control bones
  • +
  • Extended class
  • +
  • Canvas test
  • +
  • Depth test
  • +
  • Render to texture test
  • \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/render-to-texture-test.html b/spine-ts/spine-phaser/example/render-to-texture-test.html new file mode 100644 index 000000000..64d331142 --- /dev/null +++ b/spine-ts/spine-phaser/example/render-to-texture-test.html @@ -0,0 +1,58 @@ + + + + + + + + + + Spine Phaser Example + + + +

    Render to texture

    + + + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/src/SpineGameObject.ts b/spine-ts/spine-phaser/src/SpineGameObject.ts index d034922b1..32c60949e 100644 --- a/spine-ts/spine-phaser/src/SpineGameObject.ts +++ b/spine-ts/spine-phaser/src/SpineGameObject.ts @@ -1,8 +1,7 @@ import { SPINE_GAME_OBJECT_TYPE } from "./keys"; import { SpinePlugin } from "./SpinePlugin"; -import { ComputedSizeMixin, DepthMixin, FlipMixin, ScrollFactorMixin, TransformMixin, VisibleMixin } from "./mixins"; +import { ComputedSizeMixin, DepthMixin, FlipMixin, ScrollFactorMixin, TransformMixin, VisibleMixin, AlphaMixin } from "./mixins"; import { AnimationState, AnimationStateData, Bone, MathUtils, Skeleton, Skin, Vector2 } from "@esotericsoftware/spine-core"; -import { Vector3 } from "@esotericsoftware/spine-webgl"; class BaseSpineGameObject extends Phaser.GameObjects.GameObject { constructor (scene: Phaser.Scene, type: string) { @@ -76,7 +75,7 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro } } -export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(BaseSpineGameObject)))))) { +export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject))))))) { blendMode = -1; skeleton: Skeleton | null = null; animationStateData: AnimationStateData | null = null; @@ -89,7 +88,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro constructor (scene: Phaser.Scene, private plugin: SpinePlugin, x: number, y: number, dataKey: string, atlasKey: string, public boundsProvider: SpineGameObjectBoundsProvider = new SetupPoseBoundsProvider()) { super(scene, SPINE_GAME_OBJECT_TYPE); - this.setPosition(x, y); x + this.setPosition(x, y); this.setSkeleton(dataKey, atlasKey); } diff --git a/spine-ts/spine-phaser/src/SpinePlugin.ts b/spine-ts/spine-phaser/src/SpinePlugin.ts index e9520d7eb..49d96770a 100644 --- a/spine-ts/spine-phaser/src/SpinePlugin.ts +++ b/spine-ts/spine-phaser/src/SpinePlugin.ts @@ -106,13 +106,16 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin { }; let makeSpineGameObject = function (this: Phaser.GameObjects.GameObjectFactory, config: any, addToScene: boolean) { + let x = config.x ? config.x : 0; + let y = config.y ? config.y : 0; let dataKey = config.dataKey ? config.dataKey : null; let atlasKey = config.atlasKey ? config.atlasKey : null; - let gameObject = new SpineGameObject(this.scene, self, 0, 0, dataKey, atlasKey); + let boundsProvider = config.boundsProvider ? config.boundsProvider : undefined; + let gameObject = new SpineGameObject(this.scene, self, x, y, dataKey, atlasKey, boundsProvider); if (addToScene !== undefined) { config.add = addToScene; } - Phaser.GameObjects.BuildGameObject(this.scene, gameObject, config); + return Phaser.GameObjects.BuildGameObject(this.scene, gameObject, config); } pluginManager.registerGameObject(SPINE_GAME_OBJECT_TYPE, addSpineGameObject, makeSpineGameObject); } diff --git a/spine-ts/spine-phaser/src/mixins.ts b/spine-ts/spine-phaser/src/mixins.ts index 63ab0810d..f4995daad 100644 --- a/spine-ts/spine-phaser/src/mixins.ts +++ b/spine-ts/spine-phaser/src/mixins.ts @@ -31,6 +31,7 @@ export const Flip = components.Flip; export const ScrollFactor = components.ScrollFactor; export const Transform = components.Transform; export const Visible = components.Visible; +export const Alpha = components.Alpha; export interface Type< T, @@ -75,3 +76,5 @@ export const TransformMixin: TransformMixin = createMixin; export const VisibleMixin: VisibleMixin = createMixin(Visible); +type AlphaMixin = Mixin; +export const AlphaMixin: AlphaMixin = createMixin(Alpha); \ No newline at end of file