@@ -268,11 +268,11 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
268
268
tileset.firstGid = _currentFirstGID;
269
269
_currentFirstGID = 0 ;
270
270
}
271
- tileset.spacing = [[attributeDict objectForKey: @" spacing" ] intValue ]/ _contentScale;
272
- tileset.margin = [[attributeDict objectForKey: @" margin" ] intValue ]/ _contentScale;
271
+ tileset.spacing = [[attributeDict objectForKey: @" spacing" ] intValue ] / _contentScale;
272
+ tileset.margin = [[attributeDict objectForKey: @" margin" ] intValue ] / _contentScale;
273
273
CGSize s;
274
- s.width = [[attributeDict objectForKey: @" tilewidth" ] intValue ]/ _contentScale;
275
- s.height = [[attributeDict objectForKey: @" tileheight" ] intValue ]/ _contentScale;
274
+ s.width = [[attributeDict objectForKey: @" tilewidth" ] intValue ] / _contentScale;
275
+ s.height = [[attributeDict objectForKey: @" tileheight" ] intValue ] / _contentScale;
276
276
tileset.tileSize = s;
277
277
tileset.tileOffset = CGPointZero; // default offset (0,0)
278
278
tileset.contentScale = _contentScale;
@@ -303,6 +303,8 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
303
303
CGSize s;
304
304
s.width = [[attributeDict objectForKey: @" width" ] intValue ];
305
305
s.height = [[attributeDict objectForKey: @" height" ] intValue ];
306
+
307
+ // The layer size is the row * column
306
308
layer.layerSize = s;
307
309
308
310
layer.visible = ![[attributeDict objectForKey: @" visible" ] isEqualToString: @" 0" ];
@@ -313,9 +315,10 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
313
315
layer.opacity = 1.0 ;
314
316
}
315
317
316
- int x = [[attributeDict objectForKey: @" x" ] intValue ];
317
- int y = [[attributeDict objectForKey: @" y" ] intValue ];
318
- layer.offset = ccp (x,y);
318
+ CGPoint offset;
319
+ offset.x = [[attributeDict objectForKey: @" offsetx" ] floatValue ];
320
+ offset.y = [[attributeDict objectForKey: @" offsety" ] floatValue ];
321
+ layer.offset = ccpMult (offset , 1 / _contentScale);
319
322
320
323
[_layers addObject: layer];
321
324
@@ -327,9 +330,9 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
327
330
CCTiledMapObjectGroup *objectGroup = [[CCTiledMapObjectGroup alloc ] init ];
328
331
objectGroup.groupName = [attributeDict objectForKey: @" name" ];
329
332
CGPoint positionOffset;
330
- positionOffset.x = [[attributeDict objectForKey: @" x " ] intValue ] * _tileSize. width ;
331
- positionOffset.y = [[attributeDict objectForKey: @" y " ] intValue ] * _tileSize. height ;
332
- objectGroup.positionOffset = positionOffset;
333
+ positionOffset.x = [[attributeDict objectForKey: @" offsetx " ] floatValue ] ;
334
+ positionOffset.y = [[attributeDict objectForKey: @" offsety " ] floatValue ] ;
335
+ objectGroup.positionOffset = ccpMult ( positionOffset, 1 / _contentScale) ;
333
336
334
337
[_objectGroups addObject: objectGroup];
335
338
@@ -386,14 +389,14 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
386
389
// X
387
390
NSString *value = [attributeDict objectForKey: @" x" ];
388
391
if ( value ) {
389
- int x = [value intValue ] + objectGroup.positionOffset .x ;
392
+ int x = [value intValue ] / _contentScale + objectGroup.positionOffset .x ;
390
393
[dict setObject: [NSNumber numberWithInt: x] forKey: @" x" ];
391
394
}
392
395
393
396
// Y
394
397
value = [attributeDict objectForKey: @" y" ];
395
398
if ( value ) {
396
- int y = [value intValue ] + objectGroup.positionOffset .y ;
399
+ int y = [value intValue ] / _contentScale + objectGroup.positionOffset .y ;
397
400
398
401
// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
399
402
y = (_mapSize.height * _tileSize.height ) - y - [[attributeDict objectForKey: @" height" ] intValue ];
0 commit comments