Вопрос

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

Это было полезно?

Решение

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.

Другие советы

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;
    }

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top