Import Cocos2d tile Map

Source: Internet
Author: User

The previous section describes how to use Tiled to create a tile map. The following section describes how to import a map to the game. Step 1: import the generated file into the resource, which is map and image set. Step 2: modify the code in HelloWorldLayer. h. It is better to understand the basics. [Objc] # 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; // map file CCTMXLayer * background; // map file layer} @ property (nonatomic, retain) CCTMXTiledMap * tileMap; // declare tileMap @ property (nonatomic, Retain) CCTMXLayer * background; // declare background // returns a CCScene that contains the HelloWorldLayer as the only child + (CCScene *) scene; @ end (note: background is the layer of the map file. Several cctmxlayers must be declared for each layer.) Step 3: Modify HelloWorldLayer. m file 1) Add [objc] @ synthesize tileMap; @ synthesize background after implentation; 2) Add in dealloc (it should be garbage processing because object-c does not have this mechanism, to be manually processed) [objc]-(void) dealloc {self. tileMap = nil; self. background = nil; // in Case you have something to dealloc, do it in this method // in this particle example nothing needs to be released. // cocos2d will automatically release all the children (Label) // don't forget to call "super dealloc" [super dealloc];} 3) replace init [objc]-(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 is the imported Resource Name self. background = [tileMap layerNamed: @ "Ground"]; // Ground is the final program generated by the layer name [self addChild: tileMap z:-1];} return self.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.