@@ -217,27 +217,29 @@ Phaser.TilemapParser = {
217217 continue ;
218218 }
219219
220+ var curl = json . layers [ i ] ;
221+
220222 var layer = {
221223
222- name : json . layers [ i ] . name ,
223- x : json . layers [ i ] . x ,
224- y : json . layers [ i ] . y ,
225- width : json . layers [ i ] . width ,
226- height : json . layers [ i ] . height ,
227- widthInPixels : json . layers [ i ] . width * json . tilewidth ,
228- heightInPixels : json . layers [ i ] . height * json . tileheight ,
229- alpha : json . layers [ i ] . opacity ,
230- visible : json . layers [ i ] . visible ,
224+ name : curl . name ,
225+ x : curl . x ,
226+ y : curl . y ,
227+ width : curl . width ,
228+ height : curl . height ,
229+ widthInPixels : curl . width * json . tilewidth ,
230+ heightInPixels : curl . height * json . tileheight ,
231+ alpha : curl . opacity ,
232+ visible : curl . visible ,
231233 properties : { } ,
232234 indexes : [ ] ,
233235 callbacks : [ ] ,
234236 bodies : [ ]
235237
236238 } ;
237239
238- if ( json . layers [ i ] . properties )
240+ if ( curl . properties )
239241 {
240- layer . properties = json . layers [ i ] . properties ;
242+ layer . properties = curl . properties ;
241243 }
242244
243245 var x = 0 ;
@@ -251,11 +253,11 @@ Phaser.TilemapParser = {
251253 // If the map contains multiple tilesets then the indexes are relative to that which the set starts from.
252254 // Need to set which tileset in the cache = which tileset in the JSON, if you do this manually it means you can use the same map data but a new tileset.
253255
254- for ( var t = 0 , len = json . layers [ i ] . data . length ; t < len ; t ++ )
256+ for ( var t = 0 , len = curl . data . length ; t < len ; t ++ )
255257 {
256258 rotation = 0 ;
257259 flipped = false ;
258- gid = json . layers [ i ] . data [ t ] ;
260+ gid = curl . data [ t ] ;
259261
260262 // If true the current tile is flipped or rotated (Tiled TMX format)
261263 if ( gid > 0x20000000 )
@@ -322,12 +324,14 @@ Phaser.TilemapParser = {
322324 }
323325 else
324326 {
325- row . push ( new Phaser . Tile ( layer , - 1 , x , output . length , json . tilewidth , json . tileheight ) ) ;
327+ // Null option
328+ // row.push(new Phaser.Tile(layer, -1, x, output.length, json.tilewidth, json.tileheight));
329+ row . push ( null ) ;
326330 }
327331
328332 x ++ ;
329333
330- if ( x === json . layers [ i ] . width )
334+ if ( x === curl . width )
331335 {
332336 output . push ( row ) ;
333337 x = 0 ;
@@ -353,21 +357,23 @@ Phaser.TilemapParser = {
353357 continue ;
354358 }
355359
360+ var curi = json . layers [ i ] ;
361+
356362 var image = {
357363
358- name : json . layers [ i ] . name ,
359- image : json . layers [ i ] . image ,
360- x : json . layers [ i ] . x ,
361- y : json . layers [ i ] . y ,
362- alpha : json . layers [ i ] . opacity ,
363- visible : json . layers [ i ] . visible ,
364+ name : curi . name ,
365+ image : curi . image ,
366+ x : curi . x ,
367+ y : curi . y ,
368+ alpha : curi . opacity ,
369+ visible : curi . visible ,
364370 properties : { }
365371
366372 } ;
367373
368- if ( json . layers [ i ] . properties )
374+ if ( curi . properties )
369375 {
370- image . properties = json . layers [ i ] . properties ;
376+ image . properties = curi . properties ;
371377 }
372378
373379 images . push ( image ) ;
@@ -446,95 +452,97 @@ Phaser.TilemapParser = {
446452 continue ;
447453 }
448454
449- objects [ json . layers [ i ] . name ] = [ ] ;
450- collision [ json . layers [ i ] . name ] = [ ] ;
455+ var curo = json . layers [ i ] ;
456+
457+ objects [ curo . name ] = [ ] ;
458+ collision [ curo . name ] = [ ] ;
451459
452- for ( var v = 0 , len = json . layers [ i ] . objects . length ; v < len ; v ++ )
460+ for ( var v = 0 , len = curo . objects . length ; v < len ; v ++ )
453461 {
454462 // Object Tiles
455- if ( json . layers [ i ] . objects [ v ] . gid )
463+ if ( curo . objects [ v ] . gid )
456464 {
457465 var object = {
458466
459- gid : json . layers [ i ] . objects [ v ] . gid ,
460- name : json . layers [ i ] . objects [ v ] . name ,
461- type : json . layers [ i ] . objects [ v ] . hasOwnProperty ( "type" ) ? json . layers [ i ] . objects [ v ] . type : "" ,
462- x : json . layers [ i ] . objects [ v ] . x ,
463- y : json . layers [ i ] . objects [ v ] . y ,
464- visible : json . layers [ i ] . objects [ v ] . visible ,
465- properties : json . layers [ i ] . objects [ v ] . properties
467+ gid : curo . objects [ v ] . gid ,
468+ name : curo . objects [ v ] . name ,
469+ type : curo . objects [ v ] . hasOwnProperty ( "type" ) ? curo . objects [ v ] . type : "" ,
470+ x : curo . objects [ v ] . x ,
471+ y : curo . objects [ v ] . y ,
472+ visible : curo . objects [ v ] . visible ,
473+ properties : curo . objects [ v ] . properties
466474
467475 } ;
468476
469- if ( json . layers [ i ] . objects [ v ] . rotation )
477+ if ( curo . objects [ v ] . rotation )
470478 {
471- object . rotation = json . layers [ i ] . objects [ v ] . rotation ;
479+ object . rotation = curo . objects [ v ] . rotation ;
472480 }
473481
474- objects [ json . layers [ i ] . name ] . push ( object ) ;
482+ objects [ curo . name ] . push ( object ) ;
475483 }
476- else if ( json . layers [ i ] . objects [ v ] . polyline )
484+ else if ( curo . objects [ v ] . polyline )
477485 {
478486 var object = {
479487
480- name : json . layers [ i ] . objects [ v ] . name ,
481- type : json . layers [ i ] . objects [ v ] . type ,
482- x : json . layers [ i ] . objects [ v ] . x ,
483- y : json . layers [ i ] . objects [ v ] . y ,
484- width : json . layers [ i ] . objects [ v ] . width ,
485- height : json . layers [ i ] . objects [ v ] . height ,
486- visible : json . layers [ i ] . objects [ v ] . visible ,
487- properties : json . layers [ i ] . objects [ v ] . properties
488+ name : curo . objects [ v ] . name ,
489+ type : curo . objects [ v ] . type ,
490+ x : curo . objects [ v ] . x ,
491+ y : curo . objects [ v ] . y ,
492+ width : curo . objects [ v ] . width ,
493+ height : curo . objects [ v ] . height ,
494+ visible : curo . objects [ v ] . visible ,
495+ properties : curo . objects [ v ] . properties
488496
489497 } ;
490498
491- if ( json . layers [ i ] . objects [ v ] . rotation )
499+ if ( curo . objects [ v ] . rotation )
492500 {
493- object . rotation = json . layers [ i ] . objects [ v ] . rotation ;
501+ object . rotation = curo . objects [ v ] . rotation ;
494502 }
495503
496504 object . polyline = [ ] ;
497505
498506 // Parse the polyline into an array
499- for ( var p = 0 ; p < json . layers [ i ] . objects [ v ] . polyline . length ; p ++ )
507+ for ( var p = 0 ; p < curo . objects [ v ] . polyline . length ; p ++ )
500508 {
501- object . polyline . push ( [ json . layers [ i ] . objects [ v ] . polyline [ p ] . x , json . layers [ i ] . objects [ v ] . polyline [ p ] . y ] ) ;
509+ object . polyline . push ( [ curo . objects [ v ] . polyline [ p ] . x , curo . objects [ v ] . polyline [ p ] . y ] ) ;
502510 }
503511
504- collision [ json . layers [ i ] . name ] . push ( object ) ;
505- objects [ json . layers [ i ] . name ] . push ( object ) ;
512+ collision [ curo . name ] . push ( object ) ;
513+ objects [ curo . name ] . push ( object ) ;
506514 }
507515 // polygon
508- else if ( json . layers [ i ] . objects [ v ] . polygon )
516+ else if ( curo . objects [ v ] . polygon )
509517 {
510- var object = slice ( json . layers [ i ] . objects [ v ] ,
518+ var object = slice ( curo . objects [ v ] ,
511519 [ "name" , "type" , "x" , "y" , "visible" , "rotation" , "properties" ] ) ;
512520
513521 // Parse the polygon into an array
514522 object . polygon = [ ] ;
515523
516- for ( var p = 0 ; p < json . layers [ i ] . objects [ v ] . polygon . length ; p ++ )
524+ for ( var p = 0 ; p < curo . objects [ v ] . polygon . length ; p ++ )
517525 {
518- object . polygon . push ( [ json . layers [ i ] . objects [ v ] . polygon [ p ] . x , json . layers [ i ] . objects [ v ] . polygon [ p ] . y ] ) ;
526+ object . polygon . push ( [ curo . objects [ v ] . polygon [ p ] . x , curo . objects [ v ] . polygon [ p ] . y ] ) ;
519527 }
520528
521- objects [ json . layers [ i ] . name ] . push ( object ) ;
529+ objects [ curo . name ] . push ( object ) ;
522530
523531 }
524532 // ellipse
525- else if ( json . layers [ i ] . objects [ v ] . ellipse )
533+ else if ( curo . objects [ v ] . ellipse )
526534 {
527- var object = slice ( json . layers [ i ] . objects [ v ] ,
535+ var object = slice ( curo . objects [ v ] ,
528536 [ "name" , "type" , "ellipse" , "x" , "y" , "width" , "height" , "visible" , "rotation" , "properties" ] ) ;
529- objects [ json . layers [ i ] . name ] . push ( object ) ;
537+ objects [ curo . name ] . push ( object ) ;
530538 }
531539 // otherwise it's a rectangle
532540 else
533541 {
534- var object = slice ( json . layers [ i ] . objects [ v ] ,
542+ var object = slice ( curo . objects [ v ] ,
535543 [ "name" , "type" , "x" , "y" , "width" , "height" , "visible" , "rotation" , "properties" ] ) ;
536544 object . rectangle = true ;
537- objects [ json . layers [ i ] . name ] . push ( object ) ;
545+ objects [ curo . name ] . push ( object ) ;
538546 }
539547 }
540548 }
@@ -611,7 +619,7 @@ Phaser.TilemapParser = {
611619 {
612620 tile = row [ k ] ;
613621
614- if ( tile . index < 0 )
622+ if ( tile === null || tile . index < 0 )
615623 {
616624 continue ;
617625 }
0 commit comments