cocos2dx popScene 使用 Transition小技巧

前端之家收集整理的这篇文章主要介绍了cocos2dx popScene 使用 Transition小技巧前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天才知道cocos2dx popScene 没有Transition,只能生硬地切换,不能忍...搜索了一下,分享小技巧~

在头文件增加两个方法

Scene * getPrevIoUsScene();

void popSceneWithTransition(Scene *trans);

Director.cpp 实现如下:

Scene * Director::getPrevIoUsScene() { ssize_t c = _scenesStack.size(); if (c <= 1) return NULL; return (Scene*)_scenesStack.at(c - 2); } void Director::popSceneWithTransition(Scene * trans) { log("popSceneWithTransition+++++++++++++++++++++++++++++++stack size = %zd",_scenesStack.size()); CCASSERT(_runningScene != NULL,"running scene should not null"); _scenesStack.popBack(); ssize_t c = _scenesStack.size(); if (c == 0) { end(); } else { _sendCleanupToScene = true; _nextScene = trans; // (CCScene*)m_pobScenesStack->objectAtIndex(c - 1); } }

用法如下:

Scene *preScene = Director::getInstance() -> getPrevIoUsScene(); TransitionScene *transition = TransitionSlideInL::create(0.3,preScene);Director::getInstance() -> popSceneWithTransition(transition); 欢迎访问我的博客helkyle.tk
原文链接:https://www.f2er.com/cocos2dx/345564.html

猜你在找的Cocos2d-x相关文章