Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(八)
生活随笔
收集整理的這篇文章主要介紹了
Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(八)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大熊貓豬·侯佩原創或翻譯作品.歡迎轉載,轉載請注明出處.
如果覺得寫的不好請告訴我,如果覺得不錯請多多支持點贊.謝謝! hopy ;)
回到Xcode中,新建一個EndLayer類,繼承于CCNode.因為我們得在其類方法中創建實例變量,所以我們得建立幾個實例變量的屬性.打開EndLayer.h文件,修改內容如下:
#import "CCNode.h"@class MainScene;@interface EndLayer : CCNode@property (nonatomic,strong) CCLabelBMFont *msgLabel; @property (nonatomic,strong) CCLabelBMFont *restartLabel; @property (nonatomic,weak) MainScene *mainScene;+(instancetype)endLayerWithMainScene:(MainScene*)mainScene message:(NSString*)msg;@end接著打開EndLayer.m文件添加如下代碼:
#import "EndLayer.h" #import "MainScene.h"@implementation EndLayer-(void)restartTapped:(id)sender{CCScene *scene = [CCBReader loadAsScene:@"MainScene"];CCTransition *transition = [CCTransition transitionFadeWithColor:[CCColor whiteColor] duration:0.5];[[CCDirector sharedDirector]replaceScene:scene withTransition:transition]; }-(void)onEnter{[super onEnter];[self.msgLabel runAction:[CCActionScaleTo actionWithDuration:0.5 scale:1.0]];[self.restartLabel runAction:[CCActionScaleTo actionWithDuration:0.5 scale:1.0]]; }+(instancetype)endLayerWithMainScene:(MainScene*)mainScene message:(NSString*)msg{EndLayer *endLayer = (EndLayer*)[CCBReader load:@"EndLayer"];endLayer.mainScene = mainScene;endLayer.msgLabel.string = msg;endLayer.msgLabel.scale = 0.1;endLayer.restartLabel.scale = 0.1;return endLayer; }@end注意我們在其onEnter方法中實現了原代碼中的菜單動畫效果,現在編譯運行app,效果如下:
OK!至此我們全部完成了原代碼的轉換工作,該系列8篇博文到此告一段落.
本貓豬將在新開辟博文”A*尋路算法的Cocos2D實現”的系列文章中,繼續CatMazeV3項目的擴展旅程,敬請期待,再會! ;)
總結
以上是生活随笔為你收集整理的Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(八)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到老公被烧伤预示着什么
- 下一篇: 梦到新手表是什么意思