运行视网膜时,TMX Map 无法正确读取对象位置?

发布于 2025-01-04 00:15:27 字数 758 浏览 6 评论 0原文

目前正在开发一款游戏,并将其转换为视网膜。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琉璃繁缕 2025-01-11 00:15:27

我找到了答案。
我必须使用 CC_CONTENT_SCALE_FACTOR() 划分检索到的 X 和 Y 位置
每次使用 tilemap.tileSize.heighttilemap.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 used tilemap.tileSize.height and tilemap.tileSize.width.

携君以终年 2025-01-11 00:15:27

我也为此苦苦挣扎了几个小时,所以我想我应该分享一下我是如何解决的:)

self.hero.position = [self ccpConvertForRetina:ccp(x, y) :self.map];

- (CGPoint) ccpConvertForRetina : (CGPoint) pointToConvert : (CCTMXTiledMap*) map {

    if (CC_CONTENT_SCALE_FACTOR() == 2) {

        float x = pointToConvert.x;
        float y = pointToConvert.y;

        float numBortHeight = map.mapSize.height;
        float tileSizeHeight = map.tileSize.height;

        float yCalc = y - (tileSizeHeight*numBortHeight) / 2;

        return CGPointMake(x,yCalc);
    }
    else {
        return pointToConvert;
    }

}

I also struggled with this for a few hours, so I thought I'd share how I solved it :)

self.hero.position = [self ccpConvertForRetina:ccp(x, y) :self.map];

- (CGPoint) ccpConvertForRetina : (CGPoint) pointToConvert : (CCTMXTiledMap*) map {

    if (CC_CONTENT_SCALE_FACTOR() == 2) {

        float x = pointToConvert.x;
        float y = pointToConvert.y;

        float numBortHeight = map.mapSize.height;
        float tileSizeHeight = map.tileSize.height;

        float yCalc = y - (tileSizeHeight*numBortHeight) / 2;

        return CGPointMake(x,yCalc);
    }
    else {
        return pointToConvert;
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文