运行视网膜时,TMX Map 无法正确读取对象位置?
目前正在开发一款游戏,并将其转换为视网膜。我正在使用 cocos2d 和 Tiled。 我已按照他们网站上的指南进行操作: Retina Display in cocos2d,但物体的位置有问题。
我现在在做什么:
NSMutableDictionary *playerSpawn = [objects objectNamed:@"SpawnPoint"];
NSAssert(playerSpawn != nil, @"Player spawn object not found");
int x = [[playerSpawn valueForKey:@"x"] intValue];
int y = [[playerSpawn valueForKey:@"y"] intValue];
self.player.position = ccp(x,y);
这个 sd TMX 贴图工作得很好,但是在 Retina 中运行时,对象的位置不正确。
如果我记录它给我的位置:
// SD
158.000000, 63.000000
// Retina
158.000000, 383.000000
赞赏我可能做错的事情
Currently working on a game, and is converting it to retina. I am using cocos2d and Tiled.
I have followed the guide on their site: Retina Display in cocos2d, but having problems with the position of objects.
What im doing right now:
NSMutableDictionary *playerSpawn = [objects objectNamed:@"SpawnPoint"];
NSAssert(playerSpawn != nil, @"Player spawn object not found");
int x = [[playerSpawn valueForKey:@"x"] intValue];
int y = [[playerSpawn valueForKey:@"y"] intValue];
self.player.position = ccp(x,y);
This sd TMX map is working just fine, but when running in Retina, the objects is not positioned correctly.
If i log the position it gives me:
// SD
158.000000, 63.000000
// Retina
158.000000, 383.000000
Ideas of what i could be doing wrong is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案。
我必须使用
CC_CONTENT_SCALE_FACTOR()
划分检索到的 X 和 Y 位置每次使用
tilemap.tileSize.height
和tilemap.tileSize.width
时,我还必须用CC_CONTENT_SCALE_FACTOR()
进行划分。I found the answer.
I had to divide my retrived X an Y positions with
CC_CONTENT_SCALE_FACTOR()
I also had to divide with
CC_CONTENT_SCALE_FACTOR()
each time i usedtilemap.tileSize.height
andtilemap.tileSize.width
.我也为此苦苦挣扎了几个小时,所以我想我应该分享一下我是如何解决的:)
I also struggled with this for a few hours, so I thought I'd share how I solved it :)