diff --git a/cocos2d-ext/TileMaps/CCTMXXMLParser.m b/cocos2d-ext/TileMaps/CCTMXXMLParser.m index b267793889f..661a1161629 100644 --- a/cocos2d-ext/TileMaps/CCTMXXMLParser.m +++ b/cocos2d-ext/TileMaps/CCTMXXMLParser.m @@ -268,11 +268,11 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name tileset.firstGid = _currentFirstGID; _currentFirstGID = 0; } - tileset.spacing = [[attributeDict objectForKey:@"spacing"] intValue]/_contentScale; - tileset.margin = [[attributeDict objectForKey:@"margin"] intValue]/_contentScale; + tileset.spacing = [[attributeDict objectForKey:@"spacing"] intValue] / _contentScale; + tileset.margin = [[attributeDict objectForKey:@"margin"] intValue] / _contentScale; CGSize s; - s.width = [[attributeDict objectForKey:@"tilewidth"] intValue]/_contentScale; - s.height = [[attributeDict objectForKey:@"tileheight"] intValue]/_contentScale; + s.width = [[attributeDict objectForKey:@"tilewidth"] intValue] / _contentScale; + s.height = [[attributeDict objectForKey:@"tileheight"] intValue] / _contentScale; tileset.tileSize = s; tileset.tileOffset = CGPointZero; //default offset (0,0) tileset.contentScale = _contentScale; @@ -303,6 +303,8 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name CGSize s; s.width = [[attributeDict objectForKey:@"width"] intValue]; s.height = [[attributeDict objectForKey:@"height"] intValue]; + + // The layer size is the row * column layer.layerSize = s; layer.visible = ![[attributeDict objectForKey:@"visible"] isEqualToString:@"0"]; @@ -313,9 +315,10 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name layer.opacity = 1.0; } - int x = [[attributeDict objectForKey:@"x"] intValue]; - int y = [[attributeDict objectForKey:@"y"] intValue]; - layer.offset = ccp(x,y); + CGPoint offset; + offset.x = [[attributeDict objectForKey:@"offsetx"] floatValue]; + offset.y = [[attributeDict objectForKey:@"offsety"] floatValue]; + layer.offset = ccpMult(offset , 1 / _contentScale); [_layers addObject:layer]; @@ -327,9 +330,9 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name CCTiledMapObjectGroup *objectGroup = [[CCTiledMapObjectGroup alloc] init]; objectGroup.groupName = [attributeDict objectForKey:@"name"]; CGPoint positionOffset; - positionOffset.x = [[attributeDict objectForKey:@"x"] intValue] * _tileSize.width; - positionOffset.y = [[attributeDict objectForKey:@"y"] intValue] * _tileSize.height; - objectGroup.positionOffset = positionOffset; + positionOffset.x = [[attributeDict objectForKey:@"offsetx"] floatValue]; + positionOffset.y = [[attributeDict objectForKey:@"offsety"] floatValue]; + objectGroup.positionOffset = ccpMult(positionOffset, 1 / _contentScale); [_objectGroups addObject:objectGroup]; @@ -386,14 +389,14 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name // X NSString *value = [attributeDict objectForKey:@"x"]; if( value ) { - int x = [value intValue] + objectGroup.positionOffset.x; + int x = [value intValue] / _contentScale + objectGroup.positionOffset.x; [dict setObject:[NSNumber numberWithInt:x] forKey:@"x"]; } // Y value = [attributeDict objectForKey:@"y"]; if( value ) { - int y = [value intValue] + objectGroup.positionOffset.y; + int y = [value intValue] / _contentScale + objectGroup.positionOffset.y; // Correct y position. (Tiled uses Flipped, cocos2d uses Standard) y = (_mapSize.height * _tileSize.height) - y - [[attributeDict objectForKey:@"height"] intValue]; diff --git a/cocos2d-ext/TileMaps/CCTiledMapLayer.m b/cocos2d-ext/TileMaps/CCTiledMapLayer.m index ac63c439354..c78bf91b9cb 100644 --- a/cocos2d-ext/TileMaps/CCTiledMapLayer.m +++ b/cocos2d-ext/TileMaps/CCTiledMapLayer.m @@ -97,14 +97,13 @@ -(id) initWithTilesetInfo:(CCTiledMapTilesetInfo*)tilesetInfo layerInfo:(CCTiled _tileWidth = mapInfo.tileSize.width; _tileHeight = mapInfo.tileSize.height; _layerOrientation = mapInfo.orientation; - - CGFloat pixelsToPoints = tex ? 1.0/tex.contentScale : 1.0; + // offset (after layer orientation is set); CGPoint offset = [self calculateLayerOffset:layerInfo.offset]; - [self setPosition:ccpMult(offset, pixelsToPoints)]; + [self setPosition:offset]; - [self setContentSize:CGSizeMake( _mapColumns * _tileWidth * pixelsToPoints, _mapRows * _tileHeight * pixelsToPoints )]; + [self setContentSize:CGSizeMake( _mapColumns * _tileWidth, _mapRows * _tileHeight)]; _useAutomaticVertexZ= NO; _vertexZvalue = 0;