今天才知道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