您当前的位置: 首页 >  游戏

Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(八)

发布时间:2015-11-21 14:54:27 ,浏览量:0

大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! 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项目的扩展旅程,敬请期待,再会! ;)

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0477s