TMX Retina Display

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)];

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值