Cocos2d瓦片地图的导入
第一步:将生成的文件导入resource中,如图,分别为地图和图片集 第二步:在HelloWorldLayer.h中修改代码,有一定基础的人还是比较好理解的。[objc] view plaincopy
- #import <GameKit/GameKit.h>
- // When you import this file, you import all the cocos2d classes
- #import "cocos2d.h"
- // HelloWorldLayer
- @interface HelloWorldLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate>
- {
- CCTMXTiledMap *tileMap;//地图文件
- CCTMXLayer *background;//地图文件的一个层
- }
- @property(nonatomic,retain)CCTMXTiledMap *tileMap;//声明tileMap
- @property(nonatomic,retain)CCTMXLayer *background;//声明background
- // returns a CCScene that contains the HelloWorldLayer as the only child
- +(CCScene *) scene;
- @end

[objc] view plaincopy
- @synthesize tileMap;
- @synthesize background;
- - (void) dealloc
- {
- self.tileMap=nil;
- self.background=nil;
- // in case you have something to dealloc, do it in this method
- // in this particular example nothing needs to be released.
- // cocos2d will automatically release all the children (Label)
- // don't forget to call "super dealloc"
- [super dealloc];
- }
- -(id) init
- {
- // always call "super" init
- // Apple recommends to re-assign "self" with the "super's" return value
- if( (self=[super init]) ) {
- self.tileMap=[CCTMXTiledMap tiledMapWithTMXFile:@"desert.tmx"];//desert.tmx是导入资源名
- self.background=[tileMap layerNamed:@"Ground"];//Ground是图层名
- [self addChild:tileMap z:-1];
- }
- return self;
- }
