TMX 高清模式

来源:互联网 发布:js全屏幻灯片切换效果 编辑:程序博客网 时间:2024/03/29 09:37

TMX Retina  

For anyone trying to make this retina-compatible, here's what I did:


1) You'll need 2 sets of files. Cocos2d will automatically use the HD files if they are named properly:
  • TileMap.tmx (50x50 map, 32x32 tilesize)
  • TileMap-hd.tmx (50x50 map, 64x64 tilesize)
  • tile_textures.png (32x32 tileset)
  • tile_textures-hd.png (64x64 tileset)

2) Cocos2d handles retina locations in points, not pixels. So anytime you are calculating map size or coordinates, you need to use points. For example, on retina devices, tileMap.tileSize.width = 64 pixels, which is actually 32 points. Here are two helper functions:
CODE: SELECT ALL
-(CGPoint) pixelToPoint:(CGPoint) pixelPoint{
  return ccpMult(pixelPoint, 1/CC_CONTENT_SCALE_FACTOR());
}
-(CGSize) pixelToPointSize:(CGSize) pixelSize{
  return CGSizeMake((pixelSize.width / CC_CONTENT_SCALE_FACTOR()), (pixelSize.height / CC_CONTENT_SCALE_FACTOR()));
}

So, instead of using tileMap.tileSize, use this variable instead:
CODE: SELECT ALL
CGSize tileSize = [self pixelToPointSize:tileMap.tileSize];

You'll want to change the spawn location calculation as well:
CODE: SELECT ALL
int x = [[spawnPoint valueForKey:@"x"] intValue];
int y = [[spawnPoint valueForKey:@"y"] intValue];

self.player = [CCSprite spriteWithFile:@"Player.png"];
_player.position = [self pixelToPoint:ccp(x, y)];

原创粉丝点击