Cocos2d-iphone magic tower layer 20 Part 1

Source: Internet
Author: User

To create this game, we must first learn how to use the Titled map editor. I will not explain in detail how to use the map editor here. There are tutorials in the himi and Zilong mountain blogs, if you are interested, you can go and have a look. After the map is created, the game map has eight layers: heroPoint: Hero floor transfer point, door: door, downfloor: Down stair, upfloor: up stair, enemy: enemy, item: item, road: road, wall: the wall preparation work is here. Next we start to create a new project named "Mota", as shown in: after the project is created, run it. After the project is successfully run, delete the HelloWorldLayer file and create two files, Menu and Scenemanager, as shown in: Menu. h file code: # import <Foundation/Foundation. h> # import "cocos2d. h "# import" Scenemanager. h "// Menu @ interface Menu: CCLayer {} @ end Menu. m file code # import "Menu. h "@ implementation Menu-(id) init {if (self = [super init]) {CGSize size = [[CCDirector shareddire] winSize]; // obtain the screen size // The background image CCTMXTiledMap * tilemap = [CCTMXTiledMaptiledMapWithTMXFile: @ "background. tmx "]; tilemap. scale = 1.5; tilemap. anchorPoint = CGPointZero; [selfaddChild: tilemap]; // set the menu item style CCSprite * mota = [CCSprite spriteWithFile: @ "Magic tower .png"]; mota. position = ccp (size. width/2 + 15, size. height-150); [selfaddChild: mota]; CCSprite * magic = [CCSprite spriteWithFile: @ "magic.png"]; magic. position = ccp (size. width/2, size. height-280); [selfaddChild: magic]; // Add menu item CCSprite * playsp1 = [CCSprite spriteWithFile: @ "playGame.png"]; CCSprite * playsp2 = [CCSprite spriteWithFile: @ "playGame.png"]; playsp2.position = ccp (-20,-10); playsp2.scale = 1.1; CCMenuItemSprite * play = [prop: playsp1selectedSprite: playsp2target: selfselector: @ selector (Play)]; CCSprite * introducesp1 = [CCSprite spriteWithFile: @ "gameintroduce.png"]; CCSprite * introducesp2 = [CCSprite spriteWithFile: @ "guest"]; introducesp2.position = ccp (-20,-10); introducesp2.scale = 1.1; CCMenuItemSprite * introduce = [weight: Weight: introducesp2target: selfselector: @ selector (Pntroduce)]; CCSprite * exitsp1 = [CCSprite spriteWithFile: @ "exitGame.png"]; CCSprite * exitsp2 = [CCSprite spriteWithFile: @ "blank"]; exitsp2.position = ccp (-20,-10 ); exitsp2.scale = 1.1; CCMenuItemSprite * exit = [Export: exitsp2target: selfselector: @ selector (Exit)]; CCMenu * menu = [CCMenu menuWithItems: play, introduce, exit, nil]; // [menualignItemsVertically]; [selfaddChild: menu]; play. position = ccp (0, 0); introduce. position = ccp (0,-100); exit. position = ccp (0,-210);} returnself;}-(void) Play {[ScenemanagergoPlay];}-(void) Pntroduce {}-(void) exit {[[ccdirectorsharedctor] end]; # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) exit (0); # endif} @ endScenemanager. h file code # import <Foundation/Foundation. h> # import "cocos2d. h "// scenario manager @ interface Scenemanager: CCLayer {CCScene * scene;} // switch scenario + (void) goMenu; + (void) goPlay; @ endScenemanager. m file code # import "Scenemanager. h "# import" Menu. h "// defines the private class method @ interfaceScenemanager () + (void) go :( CCLayer *) layer; + (CCScene *) wray :( CCLayer *) layer; @ end @ implementation Scenemanager // enter the Menu + (void) goMenu {CCLayer * layer = [Menu node]; [Scenemanagergo: layer];} // start the game + (void) goPlay {} // switching scenario + (void) go :( CCLayer *) layer {CCDirector * director = [CCDirector shareddire]; CCScene * newScene = [Scenemanager wray: layer]; if ([director runningScene]) {[director replaceScene: newScene];} else {[director runWithScene: newScene];} // initialization scenario + (CCScene *) wray :( CCLayer *) layer {CCScene * newScene = [CCScene node]; [newScene addChild: layer]; return newScene ;}@ end next find AppDelegate. in the m file, find the code and modify it to find the code. After the code is modified to complete, the Start menu will appear:

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.