简体   繁体   中英

How to use isometric orientation, cocos2d, iOS, CCTMXTiledMap

I'm trying to grasp the basics of tile-based games (cocos2D, iOS development). I use "Tiled" - application, which makes .tmx files, which are used as tile maps. I succeeded to load orthogonal orientation, but I have some problems with isometric orientation: when I load .tmx file, nothing is displayed:

-(id) init
{
if ((self = [super init]))
{
    CCTMXTiledMap* tileMap = [CCTMXTiledMap        tiledMapWithTMXFile:@"isometric.tmx"];
    [self addChild:tileMap z:1];
}
return self;
}

As a result, I get black screen despite the fact I added background (simple green grass). My question is what am I doind wrongly and why it doesn't display background?

The visible part of an isometric tilemap is a rhombus . The default position of the tilemap is at 0,0, the lower left corner. If your iso tilemap is large enough it's possible that you don't see anything because you're looking at the part of the rhombus' bounding rectangle that doesn't contain any tiles. You need to move the tilemap into view.

Try this for example:

tileMap.position = CGPointMake(-500, -500);

This moves the position of the tilemap 500 pixels to the left and 500 down. It has the same effect as moving the viewport (iPhone screen) over the tilemap towards the right and up. Depending on the size of your tilemap tweak the position until you can see the iso map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM