@@ -69,7 +69,7 @@ Phaser.Animation.Parser = {
6969 * @param json {object} Json data you want to parse.
7070 * @return {FrameData } Generated FrameData object.
7171 */
72- JSONData : function ( game , json ) {
72+ JSONData : function ( game , json , cacheKey ) {
7373
7474 // Malformed?
7575 if ( ! json [ 'frames' ] ) {
@@ -84,25 +84,41 @@ Phaser.Animation.Parser = {
8484 var frames = json [ 'frames' ] ;
8585 var newFrame ;
8686
87- for ( var i = 0 ; i < frames . length ; i ++ ) {
87+ for ( var i = 0 ; i < frames . length ; i ++ )
88+ {
89+ var uuid = game . rnd . uuid ( ) ;
8890
8991 newFrame = data . addFrame ( new Phaser . Animation . Frame (
9092 frames [ i ] . frame . x ,
9193 frames [ i ] . frame . y ,
9294 frames [ i ] . frame . w ,
9395 frames [ i ] . frame . h ,
94- frames [ i ] . filename
96+ frames [ i ] . filename ,
97+ uuid
9598 ) ) ;
9699
97- newFrame . setTrim (
98- frames [ i ] . trimmed ,
99- frames [ i ] . sourceSize . w ,
100- frames [ i ] . sourceSize . h ,
101- frames [ i ] . spriteSourceSize . x ,
102- frames [ i ] . spriteSourceSize . y ,
103- frames [ i ] . spriteSourceSize . w ,
104- frames [ i ] . spriteSourceSize . h
105- ) ;
100+ PIXI . TextureCache [ uuid ] = new PIXI . Texture ( PIXI . BaseTextureCache [ cacheKey ] , {
101+ x : frames [ key ] . frame . x ,
102+ y : frames [ key ] . frame . y ,
103+ width : frames [ key ] . frame . w ,
104+ height : frames [ key ] . frame . h
105+ } ) ;
106+
107+ if ( frames [ i ] . trimmed )
108+ {
109+ newFrame . setTrim (
110+ frames [ i ] . trimmed ,
111+ frames [ i ] . sourceSize . w ,
112+ frames [ i ] . sourceSize . h ,
113+ frames [ i ] . spriteSourceSize . x ,
114+ frames [ i ] . spriteSourceSize . y ,
115+ frames [ i ] . spriteSourceSize . w ,
116+ frames [ i ] . spriteSourceSize . h
117+ ) ;
118+
119+ PIXI . TextureCache [ uuid ] . realSize = frames [ key ] . spriteSourceSize ;
120+ PIXI . TextureCache [ uuid ] . trim . x = 0 ;
121+ }
106122 }
107123
108124 return data ;
@@ -114,7 +130,7 @@ Phaser.Animation.Parser = {
114130 * @param json {object} Json data you want to parse.
115131 * @return {FrameData } Generated FrameData object.
116132 */
117- JSONDataHash : function ( game , json ) {
133+ JSONDataHash : function ( game , json , cacheKey ) {
118134
119135 // Malformed?
120136 if ( ! json [ 'frames' ] ) {
@@ -129,25 +145,41 @@ Phaser.Animation.Parser = {
129145 var frames = json [ 'frames' ] ;
130146 var newFrame ;
131147
132- for ( var key in frames ) {
148+ for ( var key in frames )
149+ {
150+ var uuid = game . rnd . uuid ( ) ;
133151
134152 newFrame = data . addFrame ( new Phaser . Animation . Frame (
135153 frames [ key ] . frame . x ,
136154 frames [ key ] . frame . y ,
137155 frames [ key ] . frame . w ,
138156 frames [ key ] . frame . h ,
139- key
157+ key ,
158+ uuid
140159 ) ) ;
141160
142- newFrame . setTrim (
143- frames [ key ] . trimmed ,
144- frames [ key ] . sourceSize . w ,
145- frames [ key ] . sourceSize . h ,
146- frames [ key ] . spriteSourceSize . x ,
147- frames [ key ] . spriteSourceSize . y ,
148- frames [ key ] . spriteSourceSize . w ,
149- frames [ key ] . spriteSourceSize . h
150- ) ;
161+ PIXI . TextureCache [ uuid ] = new PIXI . Texture ( PIXI . BaseTextureCache [ cacheKey ] , {
162+ x : frames [ key ] . frame . x ,
163+ y : frames [ key ] . frame . y ,
164+ width : frames [ key ] . frame . w ,
165+ height : frames [ key ] . frame . h
166+ } ) ;
167+
168+ if ( frames [ key ] . trimmed )
169+ {
170+ newFrame . setTrim (
171+ frames [ key ] . trimmed ,
172+ frames [ key ] . sourceSize . w ,
173+ frames [ key ] . sourceSize . h ,
174+ frames [ key ] . spriteSourceSize . x ,
175+ frames [ key ] . spriteSourceSize . y ,
176+ frames [ key ] . spriteSourceSize . w ,
177+ frames [ key ] . spriteSourceSize . h
178+ ) ;
179+
180+ PIXI . TextureCache [ uuid ] . realSize = frames [ key ] . spriteSourceSize ;
181+ PIXI . TextureCache [ uuid ] . trim . x = 0 ;
182+ }
151183 }
152184
153185 return data ;
@@ -159,7 +191,7 @@ Phaser.Animation.Parser = {
159191 * @param xml {object} XML data you want to parse.
160192 * @return {FrameData } Generated FrameData object.
161193 */
162- XMLData : function ( game , xml , format ) {
194+ XMLData : function ( game , xml , cacheKey ) {
163195
164196 // Malformed?
165197 if ( ! xml . getElementsByTagName ( 'TextureAtlas' ) ) {
@@ -171,7 +203,9 @@ Phaser.Animation.Parser = {
171203 var frames = xml . getElementsByTagName ( 'SubTexture' ) ;
172204 var newFrame ;
173205
174- for ( var i = 0 ; i < frames . length ; i ++ ) {
206+ for ( var i = 0 ; i < frames . length ; i ++ )
207+ {
208+ var uuid = game . rnd . uuid ( ) ;
175209
176210 var frame = frames [ i ] . attributes ;
177211
@@ -180,9 +214,17 @@ Phaser.Animation.Parser = {
180214 frame . y . nodeValue ,
181215 frame . width . nodeValue ,
182216 frame . height . nodeValue ,
183- frame . name . nodeValue
217+ frame . name . nodeValue ,
218+ uuid
184219 ) ) ;
185220
221+ PIXI . TextureCache [ uuid ] = new PIXI . Texture ( PIXI . BaseTextureCache [ cacheKey ] , {
222+ x : frame . x . nodeValue ,
223+ y : frame . y . nodeValue ,
224+ width : frame . width . nodeValue ,
225+ height : frame . height . nodeValue
226+ } ) ;
227+
186228 // Trimmed?
187229 if ( frame . frameX . nodeValue != '-0' || frame . frameY . nodeValue != '-0' ) {
188230 newFrame . setTrim (
@@ -194,6 +236,16 @@ Phaser.Animation.Parser = {
194236 frame . frameWidth . nodeValue ,
195237 frame . frameHeight . nodeValue
196238 ) ;
239+
240+ PIXI . TextureCache [ uuid ] . realSize = {
241+ x : Math . abs ( frame . frameX . nodeValue ) ,
242+ y : Math . abs ( frame . frameY . nodeValue ) ,
243+ w : frame . frameWidth . nodeValue ,
244+ h : frame . frameHeight . nodeValue
245+ } ;
246+
247+ PIXI . TextureCache [ uuid ] . trim . x = 0 ;
248+
197249 }
198250 }
199251
0 commit comments