Source

cocos2d-qt / Srcs / transitionscene.cpp

Full commit
#include "transitionscene.h"


transitionScene::transitionScene() {

}

transitionScene * transitionScene::FadeTransition(Scene *otherScene,float duration) {
    transitionScene* newTrans = new transitionScene;
    newTrans->nextScene = otherScene;
    otherScene->mainLayer->onEnterTransitionDidStart();
    newTrans->dur = duration;
    newTrans->origFade = newTrans->nextScene->opacity();
    newTrans->nextScene->setOpacity(0);
    connect(newTrans,SIGNAL(transitionDoneSignal(Scene*)),Director::sharedDirector(),SLOT(transitionDone(Scene*)));
    return newTrans;
}

void transitionScene::setCurrScene(Scene *scene) {
    currScene = scene;
    currScene->mainLayer->onExitTransitionDidStart();
    Action* firststep = Action::fadeTo(dur/2,0);
    Action* gotostep2 = Action::FuncCall(this,SLOT(FadeTransition_half_done()));
    scene->runSequence(Sequence::sequenceWithActions(firststep,gotostep2,NULL));
}

void transitionScene::FadeTransition_half_done() {
    Action* firststep = Action::fadeTo(dur/2,origFade);
    Action* gotostep3 = Action::FuncCall(this,SLOT(transition_done()));
    nextScene->runSequence(Sequence::sequenceWithActions(firststep,gotostep3,NULL));
}
void transitionScene::transition_done() {
    currScene->mainLayer->onExitTransitionDidFinish();
    nextScene->mainLayer->onEnterTransitionDidFinish();
    emit transitionDoneSignal(nextScene);
    deleteLater();
}