Exemple #1
0
void SceneManager::changeScene( EnumSceneType enScenType, bool isTrans, float time )
{
    Scene* pScene = getSceneByType(enScenType);
    
    if(pScene == NULL)
    {
        return;
    }
    //TextureCache::sharedTextureCache()->removeUnusedTextures();
    Director* pDirector = Director::getInstance();
    Scene* curScene = pDirector->getRunningScene();
    if(curScene == NULL)
    {
        pDirector->runWithScene(pScene);
    }
    else
    {
        if(isTrans)
        {
            pDirector->replaceScene(TransitionFade::create(time, pScene));
        }
        else
        {
            pDirector->replaceScene(pScene);
        }
    }
}
Exemple #2
0
bool CGameSceneManager::go(SCENE_TYPE st)
{
    Scene* scene = nullptr;
    switch (st)
    {
        case ST_LOGIN:
        {
            CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance());
            scene = pReader->createSceneWithNodeGraphFromFile("login_layer.ccbi");
            delete pReader;
            break;
        }
        case ST_LOBBY:
        {
            CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance());
            scene = pReader->createSceneWithNodeGraphFromFile("lobby_layer.ccbi");
            delete pReader;
            break;
        }
        case ST_FORMATION:
        {
            scene = Scene::create();
            scene->addChild(CFormationLayer::create());
            break;
        }
        case ST_BATTLE_FIELD:
        {
            scene = Scene::create();
            scene->addChild(CBattleFieldLayer::create());       // call init in create()
            break;
        }
        case ST_SETTINGS:
            break;
        case ST_HOME:
        {
            CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance());
            scene = pReader->createSceneWithNodeGraphFromFile("home_layer.ccbi");
            delete pReader;
            break;
        }
        default:
            break;
    }
    if (scene)
    {
        Director* pDirector = Director::getInstance();
        if (pDirector->getRunningScene())
        {
            TransitionFade* trans = TransitionFade::create(.2f, scene, Color3B(255, 255, 255));
            pDirector->replaceScene(trans);
        }
        else
        {
            pDirector->runWithScene(scene);
        }
    }
    
    return true;
}
void MainLoadingScene::finishLoading()
{
    Scene *scene = MainMenuScene::create();

    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
Exemple #4
0
void LevelScene::backButton(Ref* sender)
{
    SimpleAudioEngine::getInstance()->playEffect(std::string(FileUtils::getInstance()->fullPathForFilename("sounds/button.wav")).c_str());
    CategoryScene *scene = CategoryScene::create();
    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
Exemple #5
0
void BukatutaLayer::buttonClicked(Ref *pSender, cocos2d::extension::Control::EventType pCCControlEvent) {
    
    CategoryScene *scene = CategoryScene::create();
    
    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
Exemple #6
0
void CreditsScene::backToMenu()
{
    PLAYEFFECT;
    
    Director *director = Director::getInstance();
    Scene *scene = MainMenuScene::scene();
    TransitionFade *transitionScene = TransitionFade::create(0.5, scene);
    director->replaceScene(transitionScene);
}
void menuCallback(Object *sender)
{
    Scene *s = Scene::create();
    BackgroundLayer *gLayer = BackgroundLayer::create();
    s->addChild(gLayer);

    GameLayer *pLayer = GameLayer::create();
    s->addChild(pLayer, 1);

    Director *pDirector = Director::getInstance();
    pDirector->replaceScene(s);
}
void SceneManager::fillStack()
{
	// Get instance of director
	Director* director = Director::getInstance();

	// Empty the stack
	director->popToRootScene();

	// Add scenes to stack
	director->replaceScene(TransitionFade::create(4, generateLevel(1, 0), Color3B::BLACK));
	level = 1;
}
void MainMenuScene::menuTouchCallBack(cocos2d::CCObject *pSender)
{
    CCMenuItem* pMenuItem = (CCMenuItem *)pSender;
    
    Director *director = Director::getInstance();
    
    switch (pMenuItem->getTag()) {
        case 1: {
            CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sound/MainBGM.mp3", true);
            
			MapScene* gameScene = MapScene::create();
            director->replaceScene(TransitionFade::create(1.0f, gameScene));
            break;
        }
        case 2:{
            Scene* creditScene = CreditScene::createScene();
            director->replaceScene(TransitionFade::create(1.0f,creditScene));
            break;
        }
    }
}
void GalderaScene::backButton(Ref* sender)
{
    multzoa->kalifikazioa = kalifikazioa;
    multzoa->currentGaldera = currentGalderaPosition;
    multzoa->bukatuta = 0;
    
    pSQL->updateErabiltzaileMultzoa(multzoa);
    
    CategoryScene *scene = CategoryScene::create();
    
    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
void GalderaScene::finish()
{
    multzoa->kalifikazioa = kalifikazioa;
    multzoa->currentGaldera = currentGalderaPosition;
    multzoa->bukatuta = 1;
    
    pSQL->updateErabiltzaileMultzoa(multzoa);
    
    BukatutaScene *scene = BukatutaScene::create(multzoa);
    
    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
Exemple #12
0
bool TimeUpMenuLayer::init() {
    if(!LayerColor::init()) {
        return false;
    }
    
    Director* director = Director::getInstance();
    Vec2 visibleOrigin = director->getVisibleOrigin();
    Size visibleSize = director->getVisibleSize();
    
    //    setContentSize(visibleSize);
    
    Widget* mainMenuLayer = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/time_up_menu.json");
    addChild(mainMenuLayer);
    mainMenuLayer->setContentSize(visibleSize);
    
    Node* mainMenu = mainMenuLayer->getChildByName("content");
    mainMenu->setPositionY((visibleSize.height-mainMenu->getContentSize().height)/2);
    
    Util::registerButton(mainMenu, "tryAgain", [&](Ref* ref,Widget::TouchEventType event){
        switch (event) {
            case cocos2d::ui::Widget::TouchEventType::ENDED:
            {
                m_gameLayer->reset();
                removeFromParent();
            }
                break;
            default:
                break;
        }
    }, "time_up_menu_try_again");
    
    Util::registerButton(mainMenu, "toMainMenu", [=](Ref* ref,Widget::TouchEventType event){
        switch (event) {
            case cocos2d::ui::Widget::TouchEventType::ENDED:
            {
                auto scene = MainMenuLayer::createScene();
                director->replaceScene(scene);
            }
                break;
            default:
                break;
        }
    }, "pause_menu_back_to_main_menu");
    
    Text* title = dynamic_cast<Text*>(mainMenu->getChildByName("title"));
    title->setString(LANG->getLang("time_up_menu_title"));
    
    return true;
}
Exemple #13
0
void SceneManager::go(Scene* scene)
{
	Layer* layer = (Layer*)scene;

	Director *director = Director::getInstance();
	Scene *newScene = SceneManager::wrap(layer);
	if ( director->getRunningScene() )
	{
		director->replaceScene(newScene);
	}
	else
	{
		director->runWithScene(newScene);
	}
}
Exemple #14
0
void LevelScene::levelSelected(Ref* sender)
{
    SimpleAudioEngine::getInstance()->playEffect(std::string(FileUtils::getInstance()->fullPathForFilename("sounds/button.wav")).c_str());
    SpriteButton *b = (SpriteButton*) sender;
    int position = b->getTag();
    MultzoaModel *multzoa = (MultzoaModel*) multzoak->at(position);
    if (multzoa->bukatuta == 1) {
        multzoa->bukatuta = 0;
        multzoa->kalifikazioa = 0;
        multzoa->currentGaldera = 1;
        SQLHelper *pSQLHelper = SQLHelper::getInstance();
        pSQLHelper->resetLevel(multzoa);
    }
    GalderaScene *scene = GalderaScene::create(multzoa);
    Director *pDirector = Director::getInstance();
    TransitionFade *tscene = TransitionFade::create(0.5, scene);
    pDirector->replaceScene(tscene);
}
bool CGameSceneManager::go(SCENE_TYPE st)
{
    Scene* scene = nullptr;
    switch (st)
    {
        case ST_LOGIN:
        {
            scene = CCBReadHelper::readScene("login_layer.ccbi");
            break;
        }
        case ST_LOBBY:
        {
            scene = CCBReadHelper::readScene("lobby_layer.ccbi");
            break;
        }
        case ST_MATCH:
        {
            scene = CCBReadHelper::readScene("pitch_layer.ccbi");
            break;
        }
        default:
            break;
    }
    if (scene)
    {
        Director* pDirector = Director::getInstance();
        if (pDirector->getRunningScene())
        {
            TransitionFade* trans = TransitionFade::create(.2f, scene, Color3B(255, 255, 255));
            pDirector->replaceScene(trans);
        }
        else
        {
            pDirector->runWithScene(scene);
        }
    }
    
    return true;
}
Exemple #16
0
bool IdleLayer::init() {
    if(!LayerColor::init()) {
        return false;
    }
    
    Director* director = Director::getInstance();
    Vec2 visibleOrigin = director->getVisibleOrigin();
    Size visibleSize = director->getVisibleSize();
    
    setContentSize(visibleSize);
    
    GameLayer* gameLayer = GameLayer::create(IDLE);
    gameLayer->getUiLayer()->setVisible(false);
    addChild(gameLayer);
    
//    gameLayer->setColor(Color3B::RED);
    
    Widget* idleForeground = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/idle_foreground.json");
    Node* background = idleForeground->getChildByName("background");
    background->setContentSize(visibleSize);
    
    Text* touchToStart = dynamic_cast<Text*>(idleForeground->getChildByName("touchToStart"));
    touchToStart->setString(LANG->getLang("touch_to_start"));
    touchToStart->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    touchToStart->runAction(RepeatForever::create(Blink::create(1, 1)));

    addChild(idleForeground);
    
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    eventListener->onTouchEnded = [=](Touch* touch, Event* event){
        auto scene = MainMenuLayer::createScene();
        director->replaceScene(scene);
    };
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, touchToStart);
    
    CallFunc* connectAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty() && gameLayer->getAcceptInput()) {
            auto path = game->getRandomPath();
            if(path) {
                auto front = path->getPath().front();
                auto back = path->getPath().back();
                gameLayer->doConnect(front->getX(), front->getY(), back->getX(), back->getY());
            }

        }
    });
    
    CallFunc* shuffleAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty()) {
            if (rand()%10 == 0) {
                gameLayer->doShuffle();
            }
        }
    });
    
    runAction(RepeatForever::create(Sequence::create(DelayTime::create(1.5), connectAction, shuffleAction, NULL)));
    
    return true;
}