@@ -268,11 +268,11 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
268268 tileset.firstGid = _currentFirstGID;
269269 _currentFirstGID = 0 ;
270270 }
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;
273273 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;
276276 tileset.tileSize = s;
277277 tileset.tileOffset = CGPointZero; // default offset (0,0)
278278 tileset.contentScale = _contentScale;
@@ -303,6 +303,8 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
303303 CGSize s;
304304 s.width = [[attributeDict objectForKey: @" width" ] intValue ];
305305 s.height = [[attributeDict objectForKey: @" height" ] intValue ];
306+
307+ // The layer size is the row * column
306308 layer.layerSize = s;
307309
308310 layer.visible = ![[attributeDict objectForKey: @" visible" ] isEqualToString: @" 0" ];
@@ -313,9 +315,10 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
313315 layer.opacity = 1.0 ;
314316 }
315317
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);
319322
320323 [_layers addObject: layer];
321324
@@ -327,9 +330,9 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
327330 CCTiledMapObjectGroup *objectGroup = [[CCTiledMapObjectGroup alloc ] init ];
328331 objectGroup.groupName = [attributeDict objectForKey: @" name" ];
329332 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) ;
333336
334337 [_objectGroups addObject: objectGroup];
335338
@@ -386,14 +389,14 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
386389 // X
387390 NSString *value = [attributeDict objectForKey: @" x" ];
388391 if ( value ) {
389- int x = [value intValue ] + objectGroup.positionOffset .x ;
392+ int x = [value intValue ] / _contentScale + objectGroup.positionOffset .x ;
390393 [dict setObject: [NSNumber numberWithInt: x] forKey: @" x" ];
391394 }
392395
393396 // Y
394397 value = [attributeDict objectForKey: @" y" ];
395398 if ( value ) {
396- int y = [value intValue ] + objectGroup.positionOffset .y ;
399+ int y = [value intValue ] / _contentScale + objectGroup.positionOffset .y ;
397400
398401 // Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
399402 y = (_mapSize.height * _tileSize.height ) - y - [[attributeDict objectForKey: @" height" ] intValue ];
0 commit comments