背景

在学习马里奥时,我们学习到从菜单场景到游戏场景的切换,代码如下

void CMMenuScene::OnStartCallBack( CCObject *pSender )
{CCDirector* pDirector = CCDirector::sharedDirector();CCScene *pScene = CMGameScene::CreateGameScene();pDirector->replaceScene(pScene);
}

上面的代码调用了CCDirector::replaceScene函数去进行场景切换。

CCDirector和CCScene

在cocos2dx里,CCDirector和CCScene有很密切的关系,CCDirector是导演,负责CCScene的展示,切换,结束等工作,具体体现在成员函数中:

/** Enters the Director's main loop with the given Scene.* Call it to run only your FIRST scene.* Don't call it if there is already a running scene.** It will call pushScene: and then it will call startAnimation*/void runWithScene(CCScene *pScene);/** Suspends the execution of the running scene, pushing it on the stack of suspended scenes.* The new scene will be executed.* Try to avoid big stacks of pushed scenes to reduce memory allocation. * ONLY call it if there is a running scene.*/void pushScene(CCScene *pScene);/** Pops out a scene from the queue.* This scene will replace the running one.* The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.* ONLY call it if there is a running scene.*/void popScene(void);/** Pops out all scenes from the queue until the root scene in the queue.* This scene will replace the running one.* Internally it will call `popToSceneStackLevel(1)`*/void popToRootScene(void);/** Pops out all scenes from the queue until it reaches `level`.If level is 0, it will end the director.If level is 1, it will pop all scenes until it reaches to root scene.If level is <= than the current stack level, it won't do anything.*/void popToSceneStackLevel(int level);/** Replaces the running scene with a new one. The running scene is terminated.* ONLY call it if there is a running scene.*/void replaceScene(CCScene *pScene);

以上是CCDirector的关于CCScene的成员函数

void runWithScene(CCScene *pScene):该函数是刚开始运行时,导演类展示场景

void pushScene(CCScene* scene):该函数将新的scene压入栈。在程序中有一个栈,可以保存很多场景,这样方便后退之类的操作。

void popScene(void):弹出,与pushScene对应

void popToRootScene(void):弹出栈中除了第一个场景外的其他场景

void popToSceneStackLevel(int level):弹出到制定位置的scene

void replaceScene(CCScene *pScene):让新的scene代替栈中当前的场景

动画切换

有的时候,简单的场景切换显得单调,如果需要动画切换,则需要以下类之一:

HelloWorld2* scene = HelloWorld2::create();//CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionFadeBL::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionFadeTR::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionTurnOffTiles::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionTurnOffTiles::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionJumpZoom::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionMoveInL::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionPageTurn::create(1.2, (CCScene*)scene, false));//CCDirector::sharedDirector()->replaceScene(CCTransitionRotoZoom::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionShrinkGrow::create(1.2, (CCScene*)scene));//CCDirector::sharedDirector()->replaceScene(CCTransitionSlideInL::create(1.2, (CCScene*)scene));CCDirector::sharedDirector()->replaceScene(CCTransitionCrossFade::create(1.2, (CCScene*)scene));

使用切换场景来进行场景切换,切换场景类如下所列:

CCTransitionRotoZoom//从大到小画面缩小并跳动进入
CCTransitionJumpZoom//立体从左边缩小跳动进入
CCTransitionMoveInL//从左边移动进入右边
CCTransitionMoveInR//从右边移动进入左边
CCTransitionMoveInT//从上边移动到入下边
CCTransitionMoveInB//从下边移动到入上边
CCTransitionSlideInL//从左边移动入右边
CCTransitionSlideInR//从右边移动入左边
CCTransitionSlideInT//从上边移动入下边
CCTransitionSlideInB//从下边移动入上边
CCTransitionShrinkGrow//从大到小在中间缩小进入
CCTransitionFlipX//从X轴方向立体翻转
CCTransitionFlipY//从Y轴方向立体翻转
CCTransitionFlipAngular//从右边头翻转进入
CCTransitionZoomFlipX//从X轴方向立体跳动翻转
CCTransitionZoomFlipY//从Y轴方向立体跳动翻转
CCTransitionZoomFlipAngular//从右边立体缩小翻转进入
CCTransitionFade//从中间渐变进入
CCTransitionCrossFade//从外围渐变进入
CCTransitionTurnOffTiles//从格子覆盖上层进入
CCTransitionSplitCols//竖直分三个方块切入
CCTransitionSplitRows//横向分三个方块切入
CCTransitionFadeTR//从左下角向右上角格子渐变进入
CCTransitionFadeBL//从右上角角向左下角格子渐变进入
CCTransitionFadeUp//从下向上渐变进入
CCTransitionFadeDown//从上向下渐变进入

转载于:https://www.cnblogs.com/new0801/p/6177219.html

cocos2dx进阶学习之场景切换相关推荐

  1. cocos2dx基础篇(26)——场景切换CCTransitionScene

    [唠叨] 游戏中两个场景的切换时经常要被用到的,cocos2dx引擎为我们提供了许多场景切换的动画,我感觉有些和PPT的切换很类似,所以感觉很熟悉.如:淡入淡出.翻页.跳入跳出等等. 本节要讲的场景切 ...

  2. cocos2dx进阶学习之CCTMXLayer

    继承关系 CCTMXLayer -> CCSpriteBatchNode CCTMXLayer是在瓦片地图中,抽象一个层的类,它继承自CCSpriteBatchNode,也就是说它抽象了一批相同 ...

  3. cocos2d-x游戏开发(十一)细说场景切换

    欢迎转载:http://blog.csdn.net/fylz1125/article/details/8533970 吐槽一下,刚写了一个小时,这CSDN不知抽什么风就是发不了,我以为存草稿了就刷新了 ...

  4. COCOS2DX场景切换特效

    cocos2d-x 3.0中场景切换特效比较多,而且游戏开发中也经常需要用到这些特效,来使场景切换时不至于那么干巴,遂这里汇总一下,开发中使用. 场景切换用到导演类Directory,大多数用的都是替 ...

  5. cocos2d-x初探学习笔记(6)--场景间切换效果

    小满(bill man)个人原创,欢迎转载,转载请注明地址,小满(bill man)的专栏地址http://blog.csdn.net/bill_man Cocos2d-x提供了很多场景间切换的效果, ...

  6. cocos2d-x 4.0 学习之路(七)场景切换

    场景切换 根据上一篇,我们建立了自己的MyHelloWorldScene.那么如何从HelloWorldScene切换到MyHelloWorldScene呢? 其实很简单.我们要切换场景,那么得有一个 ...

  7. Cocos2d-x学习笔记(八)—— 粒子系统,场景切换,网格特效

    粒子系统 用于在游戏的场景中生成特效,减少美工工作,可生成类似火焰,星星等的特效,效率高.为了方便开发,我们还可以利用粒子系统编辑器生成相应的plist,这里我上传了一个编辑器,当然也可从网上下载,下 ...

  8. Learning Cocos2d-x for XNA(6)——场景切换和场景过渡效果

    在进行此部分学习的时候,确保Cocos2d-x for xna引擎的版本为0.1.2(或更高版本),实测0.1.0版本部分功能出现BUG. 之前的源码都是0.1.0版本的,从此次开始都是0.1.2版本 ...

  9. cocos2dx场景切换分析之如何自定义场景切换动画

    前言:cocos2dx引擎中自带了几十种场景切换的动画,可以使场景切换的过程中平滑过渡,不至于太生硬.那么问题来了,这些动画是怎么实现的呢?如果觉得系统自带的场景切换动画太丑陋,或者满足不了我们游戏的 ...

最新文章

  1. Linux下安装搜狗拼音输入法
  2. Chromium:编译,运行
  3. [鸟哥linux视频教程整理]04_02_Linux 权限及权限管理
  4. function里面可以写function吗_和田玉不戴的时候,可以长时间泡在水里面吗?
  5. windows7系统电脑管理员权限的更改方法
  6. 使用pickle模块序列化数据,优化代码
  7. Incorporating Lexical Priors into Topic Models(即交互式主题模型的应用)论文阅读
  8. 7-5 BCD解密 (10 分)
  9. IS-IS认证原理(华为设备)
  10. Python内置函数(66)——vars
  11. (并查集)~APTX4869(fzu 2233)
  12. Mybatis-Plus注解自定义sql分页查询
  13. bootstrap入门之Code代码显示
  14. 一些wincap函数说明
  15. android中流媒体
  16. KT148A语音芯片SOP外挂功放芯片8002D的说明_V1
  17. 比光刻机还重要的IP核是什么?
  18. 2022年最流行的几款软件缺陷管理工具
  19. 预防防御鸡呼吸道疾病 鸡吃啥药防治呼吸道感染
  20. 微信小程序 python 自动化测试_微信小程序的自动化测试框架

热门文章

  1. vnpy2.0安装后报错ModuleNotFoundError: No module named 'vnpy.api.ctp.vnctpmd'
  2. 海龟交易法则02_揭秘海龟思维
  3. java 数组不重复_java如何找出数组中的不重复数字
  4. web报表工具FineReport的公式编辑框的语法简介
  5. java泛型概念与通配符含义初探
  6. 数据/方法论固然重要,但人为分析更有价值!
  7. js常用内建对象之:String对象
  8. Tomcat配置技巧Top 10
  9. 华为推出鸿蒙超级系统,华为鸿蒙系统正式发布!十个人里竟然只有两个人支持?...
  10. php 可变变量 数组赋值,PHP可变变量学习小结