@@ -13,9 +13,7 @@ var ComponentsFlip = require('../../../../src/gameobjects/components/Flip');
1313var ComponentsScrollFactor = require ( '../../../../src/gameobjects/components/ScrollFactor' ) ;
1414var ComponentsTransform = require ( '../../../../src/gameobjects/components/Transform' ) ;
1515var ComponentsVisible = require ( '../../../../src/gameobjects/components/Visible' ) ;
16- var CounterClockwise = require ( '../../../../src/math/angle/CounterClockwise' ) ;
1716var GameObject = require ( '../../../../src/gameobjects/GameObject' ) ;
18- var RadToDeg = require ( '../../../../src/math/RadToDeg' ) ;
1917var SpineGameObjectRender = require ( './SpineGameObjectRender' ) ;
2018
2119/**
@@ -86,6 +84,12 @@ var SpineGameObject = new Class({
8684
8785 setSkeleton : function ( atlasDataKey , animationName , loop , skeletonJSON )
8886 {
87+ if ( this . state )
88+ {
89+ this . state . clearListeners ( ) ;
90+ this . state . clearListenerNotifications ( ) ;
91+ }
92+
8993 var data = this . plugin . createSkeleton ( atlasDataKey , skeletonJSON ) ;
9094
9195 this . skeletonData = data . skeletonData ;
@@ -97,6 +101,8 @@ var SpineGameObject = new Class({
97101 skeleton . setSkinByName ( 'default' ) ;
98102 skeleton . setToSetupPose ( ) ;
99103
104+ this . skeleton = skeleton ;
105+
100106 // AnimationState
101107 data = this . plugin . createAnimationState ( skeleton ) ;
102108
@@ -110,78 +116,51 @@ var SpineGameObject = new Class({
110116
111117 this . stateData = data . stateData ;
112118
113- var _this = this ;
114-
115- this . state . addListener ( {
116- event : function ( trackIndex , event )
117- {
118- // Event on a Track
119- _this . emit ( 'spine.event' , _this , trackIndex , event ) ;
120- } ,
121- complete : function ( trackIndex , loopCount )
122- {
123- // Animation on Track x completed, loop count
124- _this . emit ( 'spine.complete' , _this , trackIndex , loopCount ) ;
125- } ,
126- start : function ( trackIndex )
127- {
128- // Animation on Track x started
129- _this . emit ( 'spine.start' , _this , trackIndex ) ;
130- } ,
131- end : function ( trackIndex )
132- {
133- // Animation on Track x ended
134- _this . emit ( 'spine.end' , _this , trackIndex ) ;
135- }
136- } ) ;
137-
138119 if ( animationName )
139120 {
140121 this . setAnimation ( 0 , animationName , loop ) ;
141122 }
142123
143- var renderer = this . scene . sys . renderer ;
144-
145- /*
146- var height = renderer.height;
147-
148- var oldScaleX = this.scaleX;
149- var oldScaleY = this.scaleY;
150-
151- skeleton.x = this.x;
152- skeleton.y = height - this.y;
153- skeleton.scaleX = 1;
154- skeleton.scaleY = 1;
124+ this . root = this . getRootBone ( ) ;
155125
156- skeleton.updateWorldTransform();
126+ return this . updateSize ( ) ;
127+ } ,
157128
158- this.skeleton = skeleton;
129+ setSize : function ( width , height , offsetX , offsetY )
130+ {
131+ var skeleton = this . skeleton ;
159132
160- this.root = this.getRootBone();
133+ if ( width === undefined ) { width = skeleton . data . width ; }
134+ if ( height === undefined ) { height = skeleton . data . height ; }
135+ if ( offsetX === undefined ) { offsetX = 0 ; }
136+ if ( offsetY === undefined ) { offsetY = 0 ; }
161137
162- skeleton.updateWorldTransform();
138+ this . width = width ;
139+ this . height = height ;
163140
164- var b = this.getBounds();
141+ this . displayOriginX = skeleton . x - offsetX ;
142+ this . displayOriginY = skeleton . y - offsetY ;
165143
166- // this.width = b.size.x ;
167- // this.height = b.size.y;
144+ return this ;
145+ } ,
168146
169- this.width = skeleton.data.width;
170- this.height = skeleton.data.height;
147+ setOffset : function ( offsetX , offsetY )
148+ {
149+ var skeleton = this . skeleton ;
171150
172- this.displayOriginX = this.x - b.offset.x;
173- this.displayOriginY = this.y - (height - (this.height + b.offset.y));
151+ if ( offsetX === undefined ) { offsetX = 0 ; }
152+ if ( offsetY === undefined ) { offsetY = 0 ; }
174153
175- // console.log(this.width, this.height);
176- // console.log(b.size.x, b.size.y);
177- // console.log(b.offset.x, b.offset.y);
178- // console.log(this.displayOriginX, this.displayOriginY);
154+ this . displayOriginX = skeleton . x - offsetX ;
155+ this . displayOriginY = skeleton . y - offsetY ;
179156
180- skeleton.scaleX = oldScaleX ;
181- skeleton.scaleY = oldScaleY;
157+ return this ;
158+ } ,
182159
183- skeleton.updateWorldTransform();
184- */
160+ updateSize : function ( )
161+ {
162+ var skeleton = this . skeleton ;
163+ var renderer = this . scene . sys . renderer ;
185164
186165 var height = renderer . height ;
187166
@@ -193,19 +172,15 @@ var SpineGameObject = new Class({
193172 skeleton . scaleX = 1 ;
194173 skeleton . scaleY = 1 ;
195174
196- this . skeleton = skeleton ;
197-
198- this . root = this . getRootBone ( ) ;
199-
200175 skeleton . updateWorldTransform ( ) ;
201176
202- var b = this . getBounds ( ) ;
177+ var bounds = this . getBounds ( ) ;
203178
204- this . width = b . size . x ;
205- this . height = b . size . y ;
179+ this . width = bounds . size . x ;
180+ this . height = bounds . size . y ;
206181
207- this . displayOriginX = this . x - b . offset . x ;
208- this . displayOriginY = this . y - ( height - ( this . height + b . offset . y ) ) ;
182+ this . displayOriginX = this . x - bounds . offset . x ;
183+ this . displayOriginY = this . y - ( height - ( this . height + bounds . offset . y ) ) ;
209184
210185 skeleton . scaleX = oldScaleX ;
211186 skeleton . scaleY = oldScaleY ;
@@ -215,8 +190,6 @@ var SpineGameObject = new Class({
215190 return this ;
216191 } ,
217192
218- // http://esotericsoftware.com/spine-runtimes-guide
219-
220193 getAnimationList : function ( )
221194 {
222195 var output = [ ] ;
@@ -246,7 +219,10 @@ var SpineGameObject = new Class({
246219
247220 setAnimation : function ( trackIndex , animationName , loop )
248221 {
249- this . state . setAnimation ( trackIndex , animationName , loop ) ;
222+ if ( this . findAnimation ( animationName ) )
223+ {
224+ this . state . setAnimation ( trackIndex , animationName , loop ) ;
225+ }
250226
251227 return this ;
252228 } ,
@@ -329,6 +305,41 @@ var SpineGameObject = new Class({
329305 return this . skeleton . findSlotIndex ( slotName ) ;
330306 } ,
331307
308+ findSkin : function ( skinName )
309+ {
310+ return this . skeletonData . findSkin ( skinName ) ;
311+ } ,
312+
313+ findEvent : function ( eventDataName )
314+ {
315+ return this . skeletonData . findEvent ( eventDataName ) ;
316+ } ,
317+
318+ findAnimation : function ( animationName )
319+ {
320+ return this . skeletonData . findAnimation ( animationName ) ;
321+ } ,
322+
323+ findIkConstraint : function ( constraintName )
324+ {
325+ return this . skeletonData . findIkConstraint ( constraintName ) ;
326+ } ,
327+
328+ findTransformConstraint : function ( constraintName )
329+ {
330+ return this . skeletonData . findTransformConstraint ( constraintName ) ;
331+ } ,
332+
333+ findPathConstraint : function ( constraintName )
334+ {
335+ return this . skeletonData . findPathConstraint ( constraintName ) ;
336+ } ,
337+
338+ findPathConstraintIndex : function ( pathConstraintName )
339+ {
340+ return this . skeletonData . findPathConstraintIndex ( pathConstraintName ) ;
341+ } ,
342+
332343 // getBounds ( 2-tuple offset, 2-tuple size, float[] temp): void
333344 // Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
334345 // offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
@@ -348,8 +359,6 @@ var SpineGameObject = new Class({
348359 this . state . apply ( skeleton ) ;
349360
350361 this . emit ( 'spine.update' , skeleton ) ;
351-
352- // skeleton.updateWorldTransform();
353362 } ,
354363
355364 /**
0 commit comments