1+ < html >
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < title > spine-pixi-v7</ title >
5+ < script src ="https://cdn.jsdelivr.net/npm/pixi.js@7.4.2/dist/pixi.min.js "> </ script >
6+ < script src ="../dist/iife/spine-pixi-v7.js "> </ script >
7+ < link rel ="stylesheet " href ="../../index.css ">
8+ </ head >
9+
10+ < body >
11+ < script >
12+ ( async function ( ) {
13+
14+ var app = new PIXI . Application ( {
15+ width : window . innerWidth ,
16+ height : window . innerHeight ,
17+ resolution : window . devicePixelRatio || 1 ,
18+ autoDensity : true ,
19+ resizeTo : window ,
20+ backgroundColor : 0x2c3e50 ,
21+ hello : true ,
22+ } ) ;
23+ document . body . appendChild ( app . view ) ;
24+
25+ // Pre-load the skeleton data and atlas. You can also load .json skeleton data.
26+ PIXI . Assets . add ( { alias : "spineboyData" , src : "./assets/spineboy-pro.skel" } ) ;
27+ PIXI . Assets . add ( { alias : "spineboyAtlas" , src : "./assets/spineboy-pma.atlas" } ) ;
28+ await PIXI . Assets . load ( [ "spineboyData" , "spineboyAtlas" ] ) ;
29+
30+
31+ // Create the spine display object
32+ const spineboy1 = spine . Spine . from ( { skeleton : "spineboyData" , atlas : "spineboyAtlas" , scale : .2 } ) ;
33+
34+ const spineboy2 = spine . Spine . from ( { skeleton : "spineboyData" , atlas : "spineboyAtlas" , scale : .2 ,
35+ boundsProvider : new spine . SetupPoseBoundsProvider ( ) ,
36+ } ) ;
37+
38+ const spineboy3 = spine . Spine . from ( { skeleton : "spineboyData" , atlas : "spineboyAtlas" , scale : .2 ,
39+ boundsProvider : new spine . SkinsAndAnimationBoundsProvider ( "portal" , undefined , undefined , false ) ,
40+ } ) ;
41+
42+ const spineboy4 = spine . Spine . from ( { skeleton : "spineboyData" , atlas : "spineboyAtlas" , scale : .2 ,
43+ boundsProvider : new spine . SkinsAndAnimationBoundsProvider ( "portal" , undefined , undefined , true ) ,
44+ } ) ;
45+
46+ const spineboy5 = spine . Spine . from ( { skeleton : "spineboyData" , atlas : "spineboyAtlas" , scale : .2 ,
47+ boundsProvider : new spine . AABBRectangleBoundsProvider ( - 100 , - 100 , 100 , 100 ) ,
48+ } ) ;
49+
50+ const maxHeight = spineboy3 . getBounds ( ) . height ;
51+ const scaleFactor = 1 / ( maxHeight * 5 / window . innerHeight ) ;
52+ const scaledMaxHeight = maxHeight * scaleFactor ;
53+
54+ const texts = [
55+ "Default bounds: dynamic, recomputed when queried" ,
56+ "Set up pose bound: fixed, based on setup pose" ,
57+ "Skin and animations based bound: fixed, the max AABB rectangle containing the skeleton with the given skin and given animations (clipping is ignored)" ,
58+ "Skin and animations based bound: same as above, but with clipping true. The bounds is smaller because clipped attachments' parts are not considered" ,
59+ "AABB Rectangle bounds: fixed, manually provided bounds. The origin is in skeleton root and size are in skeleton space" ,
60+ ]
61+
62+ const pointerOn = [ ] ;
63+
64+ const elements = [ spineboy1 , spineboy2 , spineboy3 , spineboy4 , spineboy5 ] . map ( ( spineboy , i ) => {
65+ // const elements = [spineboy1].map((spineboy, i) => {
66+
67+ spineboy . x = window . innerWidth / 2 ;
68+ spineboy . y = window . innerHeight / 2 + spineboy . getBounds ( ) . height / 2 ;
69+
70+ const x = 300 * scaleFactor ;
71+
72+ // spineboy placement
73+ spineboy . scale . set ( scaleFactor ) ;
74+ spineboy . state . setAnimation ( 0 , "portal" , true ) ;
75+ spineboy . x = x ;
76+ spineboy . y = 70 * scaleFactor + ( window . innerHeight / 10 * ( 1 + 2 * i ) ) ;
77+
78+ app . stage . addChild ( spineboy ) ;
79+
80+ // yellow rectangle to show bounds
81+ const graphics = new PIXI . Graphics ( ) ;
82+ app . stage . addChild ( graphics ) ;
83+
84+ // text
85+ const basicText = new PIXI . Text (
86+ texts [ i ] ,
87+ {
88+ fontSize : 20 * scaleFactor ,
89+ fill : "white" ,
90+ wordWrap : true ,
91+ wordWrapWidth : 400 * scaleFactor ,
92+ }
93+ ) ;
94+ basicText . x = x + scaledMaxHeight + 0 * scaleFactor ;
95+ basicText . y = scaledMaxHeight * ( i + .5 ) ;
96+ basicText . anchor . set ( 0 , 0.5 ) ;
97+ app . stage . addChild ( basicText ) ;
98+
99+ // pointer events
100+ spineboy . eventMode = "static" ;
101+ spineboy . cursor = "pointer" ;
102+ spineboy . on ( "pointerenter" , ( ) => pointerOn [ i ] = true ) ;
103+ spineboy . on ( "pointerleave" , ( ) => pointerOn [ i ] = false ) ;
104+
105+ return [ spineboy , graphics ] ;
106+ } )
107+
108+ app . ticker . add ( ( delta ) => {
109+ elements . forEach ( ( [ spineboy , graphic ] , i ) => {
110+ const bound = spineboy . getBounds ( ) ;
111+ graphic . clear ( ) ;
112+ graphic . lineStyle ( 2 , 0xfeeb77 ) ;
113+ graphic . beginFill ( 0xff0000 , pointerOn [ i ] ? .2 : 0 ) ;
114+ graphic . drawRect ( bound . x , bound . y , bound . width , bound . height ) ;
115+ graphic . endFill ( ) ;
116+ } )
117+ } )
118+
119+ } ) ( ) ;
120+ </ script >
121+ </ body >
122+ </ html >
0 commit comments