Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
707 views
in Technique[技术] by (71.8m points)

iphone - wrong position of tile map when i convert to retina display

I follow guide of converting tile map for retina display by changing size of width and height to double size and position of object too. but the result on normal display is not same as retina display normal display is correct but retina display is not correct

This is non-retina tile map enter image description here

and this is retina tile map enter image description here

I also add -hd suffix to retinal .tmx file

Is there something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Me also observed same problem with cocos2D tile map and finally resolved by dividing CC_CONTENT_SCALE_FACTOR. In retina mode it gives 2.0.

CCTMXObjectGroup *objects = [tileMap objectGroupNamed:NN_TILE_MAP_OBJECT_LAYER];

CGSize s = [[CCDirector sharedDirector] winSize];

NSMutableDictionary *newtonPos = [objects objectNamed:NN_NEWTON_POS];        

if(newtonPos)
{
    float x = ([[newtonPos valueForKey:@"x"] floatValue])/CC_CONTENT_SCALE_FACTOR();
    float y = [[newtonPos valueForKey:@"y"] floatValue]/CC_CONTENT_SCALE_FACTOR();

    MyGameScreen *p = (MyGameScreen*)self.parentLayer;
    p.gameActor.position = ccp(x, y);
}

//I used this function to get chord..

- (CGPoint)getTileCoordForPosition:(CGPoint)position
{
    int maxTileCol = self.mapSize.height; 

    int x = ( (position.x-self.position.x)/TILE_SIZE);
    int y = maxTileCol - ( ((position.y)-self.position.y)/TILE_SIZE);

    if( x >= TILE_IN_ROW)
        x = TILE_IN_ROW - 1;

    if( y >= TILE_IN_COL)
        y = TILE_IN_COL - 1;

    return ccp(x, y);

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...