Ejemplo n.º 1
0
void AppDelegate::onOrientationChange(int width, int height)
{
    return;
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }
    
//    glview->setFrameSize(width, height);
//    
//    //set design resolution
//    if( width < height ) {
//        
//        glview->setDesignResolutionSize(DESIGN_WIDTH, DESIGN_HEIGHT, ResolutionPolicy::SHOW_ALL);
//    }
//    else {
//        
//        glview->setDesignResolutionSize(DESIGN_HEIGHT, DESIGN_WIDTH, ResolutionPolicy::SHOW_ALL);
//    }
    
    // create a scene. it's an autorelease object
    //auto scene = HelloWorld::createScene();
    auto scene = GameScene::createScene();
    
    // run
    director->replaceScene(scene);
}
Ejemplo n.º 2
0
void GameManager::changeScene(SceneType sceneType)
{
	auto director = Director::getInstance();

	Scene* scene = nullptr;
	switch(sceneType)
	{
		case SceneType::TITLE_SCENE:
		{
			scene = TitleScene::createScene();
			break;
		}
		case SceneType::GAME_SCENE:
		{
			scene = GameScene::createScene();
			break;
		}
		default:
		{
			CCASSERT(false, "no scene to take");
			break;
		}
	}

	if(!director->getRunningScene())
	{
		director->runWithScene(scene);
	}
	else
	{
		director->replaceScene(scene);
	}
}
Ejemplo n.º 3
0
void App::gotoMenu(Ref* node)
{
	auto director = Director::getInstance();
	auto menuScene = MainMenu::createScene();
	director->replaceScene(menuScene);

	CCLOG("REPLACING with Main menu");
}
Ejemplo n.º 4
0
void App::gotoWorldLevels(Ref* node)
{
	auto director = Director::getInstance();
	auto mapScene = WorldLevels::createScene();
	director->replaceScene(mapScene);

	CCLOG("REPLACING with Levels");
}
Ejemplo n.º 5
0
void SnakeGame::menuCloseCallback(Ref* pSender)
{
	auto director = Director::getInstance();
	auto scene = GameMenu::createScene();

	// run
	director->replaceScene(scene);
}
Ejemplo n.º 6
0
void App::gotoWorldMap(Ref* node)
{
	auto director = Director::getInstance();
	auto mapScene = WorldMap::createScene();
	auto transition = TransitionFade::create(2.0f, mapScene);
	director->replaceScene(transition);

	CCLOG("REPLACING with World  map");
}
Ejemplo n.º 7
0
void PlayVedio::videoPlayOverCallback()
{
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    auto director = Director::getInstance();
	auto scene = LoginLayer::createScene();
    director->replaceScene(scene);
#endif
    
}
Ejemplo n.º 8
0
void App::startLevel(Ref* pSender)
{
	
	auto director = Director::getInstance();
	auto lvlScene = MenuScene::createScene();
	
	director->replaceScene(lvlScene);

	CCLOG("REPLACING with Level  map");

};
Ejemplo n.º 9
0
void HelloWorld::menuStartGameCallback(Ref* pSender)
{
	auto app = (AppDelegate *)Application::getInstance();
	auto fight = app->getSceneFight();
	if( fight )
	{
		auto director = Director::getInstance();
		//director->pushScene( fight );
		director->replaceScene( fight );
	}
}
Ejemplo n.º 10
0
	JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_StartJmDNS_createSceneJNI(JNIEnv *env, jobject thiz)
	{
		Director::getInstance()->getScheduler()->performFunctionInCocosThread([]() {
			auto scene = Director::getInstance()->getRunningScene();
			auto layer = (FindDeviceScene *)scene->getChildByTag(FIND_DEVICE_SCENE_TAG);
			if (layer)
			{
				layer->replaceScene(false);
			}
		});

	}
Ejemplo n.º 11
0
void PreloadScene::update(float dt)
{
    if(!m_dataStartLoading)
        PreloadData();

    if(m_dataFinishLoading)
    {
        auto director = Director::getInstance();
        auto menu = MenuScene::createScene();
        director->replaceScene(menu);
    }
}
void SceneLocalization::menuCloseCallback(Ref* pSender)
{
    // Reset the language to English(US), in case it was changed
    AK::StreamMgr::SetCurrentLanguage(AKTEXT("English(US)"));

    // Unregister the "Human" game object
    AK::SoundEngine::UnregisterGameObj(GAME_OBJECT_HUMAN);

    // Unload the sound bank
    AK::SoundEngine::UnloadBank("Human.bnk", NULL);

    auto director = Director::getInstance();
    director->replaceScene(SceneDialogueMenu::createScene());
    this->removeAllChildren();
}
Ejemplo n.º 13
0
/*--------------------------/
 戻るボタン生成
/--------------------------*/
void StageSelectActionLayer::buttonBack(){
    auto buttonImage = MenuItemImage::create("Texture/GamePlay/GameScene/StageSelect/StageSelect_Back.png",
                                             "Texture/GamePlay/GameScene/StageSelect/StageSelect_Back.png",
                                             [ = ](Ref* sender)
                                            {
                                                auto nextScene = SceneCreator::createPhysicsScene(TitleScene::create(), Vect(0, -9.8f), 5.0f);
                                                auto scene	= TransitionFade::create( 1.5f, nextScene, Color3B::BLACK );
                                                auto dir = Director::getInstance();
                                                dir->replaceScene(scene);
                                             
                                            });
    
    
    buttonImage->setPosition(1150,650);
    auto stageSelect = Menu::create( buttonImage, nullptr );
    stageSelect->setPosition( Vec2::ZERO );
    this->addChild(stageSelect,0);
}
Ejemplo n.º 14
0
/*--------------------------/
 Yesボタン生成
 /--------------------------*/
void StageSelectActionLayer::buttonYes(cocos2d::Layer* layer,Menu* menu,int tag){
    
    auto buttonYes = MenuItemImage::create("Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           "Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           [ = ](Ref* sender)
                                           {
											   UserDefault* useDef = UserDefault::getInstance();
                                               useDef->setIntegerForKey("selectStage",tag);
											   useDef->setIntegerForKey("selectGimmick", tag);
                                               useDef->flush();
                                               
                                               auto nextScene = SceneCreator::createPhysicsScene(GameMainScene::create(), Vect(0, -9.8f), 5.0f);
                                               auto scene	= TransitionFade::create( 1.5f, nextScene, Color3B::BLACK );
                                               auto dir = Director::getInstance();
                                               dir->replaceScene(scene);
                                           });
    buttonYes->setPosition(400,300);
    buttonYes->setScale(1.2f);
    menu->addChild(buttonYes);
    
}
Ejemplo n.º 15
0
void GameSceneState::switchScene(SceneState state,float t/*=0*/)
{
    Scene* scene = nullptr;
    switch (state)
    {
    case SceneState::UIGameEnter:
    {
        scene = GameEnter::createScene();
        break;
    }
    case SceneState::UIGameMain:
    {
        scene = GameMain::createScene();
        break;
    }
    case SceneState::UIGameMissionSet:
    {
        scene = GameMissionSet::createScene();
        break;
    }
    case SceneState::DDGameUILayer:
    {
        scene = GameUILayer::gameScene();
        break;
    }
    default:
        break;
    }

    //更新状态;
    m_statePrevious = m_stateLast;
    m_stateLast = m_stateNow;
    m_stateNow = state;

    replaceScene(scene,t);
}
Ejemplo n.º 16
0
void TestList::runThisTest()
{
    _cellTouchEnabled = true;
    auto director = Director::getInstance();
    auto scene = Scene::create();

    auto visibleSize = director->getVisibleSize();
    auto origin = director->getVisibleOrigin();

    auto tableView = TestCustomTableView::create(this, Size(400, visibleSize.height));
    tableView->setPosition(origin.x + (visibleSize.width - 400) / 2, origin.y);
    tableView->setDirection(ScrollView::Direction::VERTICAL);
    tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
    tableView->setDelegate(this);
    scene->addChild(tableView);
    tableView->reloadData();

    if (_shouldRestoreTableOffset)
    {
        tableView->setContentOffset(_tableOffset);
    }

    if (_parentTest)
    {
        //Add back button.
        TTFConfig ttfConfig("fonts/arial.ttf", 20);
        auto label = Label::createWithTTF(ttfConfig, "Back");

        auto menuItem = MenuItemLabel::create(label, std::bind(&TestBase::backsUpOneLevel, this));
        auto menu = Menu::create(menuItem, nullptr);

        menu->setPosition(Vec2::ZERO);
        menuItem->setPosition(Vec2(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25));

        scene->addChild(menu, 1);
    }
    else
    {
        //Add close and "Start AutoTest" button.
        auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, [](Ref* sender){
            TestController::getInstance()->stopAutoTest();
            TestController::destroyInstance();
            Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
            exit(0);
#endif
        });
        closeItem->setPosition(VisibleRect::right().x - 30, VisibleRect::top().y - 30);

        auto autoTestLabel = Label::createWithTTF("Start AutoTest","fonts/arial.ttf",16);
        auto autoTestItem = MenuItemLabel::create(autoTestLabel, [&](Ref* sender){
            TestController::getInstance()->startAutoTest();
        });
        autoTestItem->setPosition(Vec2(VisibleRect::right().x - 70, VisibleRect::bottom().y + 25));

        auto menu = Menu::create(closeItem, autoTestItem, nullptr);
        menu->setPosition(Vec2::ZERO);
        scene->addChild(menu, 1);
    }

    director->replaceScene(scene);
}
void InterstitialScene::exit(Ref* pSender)
{
    auto director = Director::getInstance();
    auto scene = MainScene::createScene();
    director->replaceScene(scene);
}
Ejemplo n.º 18
0
// on "init" you need to initialize your instance
bool GameMenu::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto label = Label::createWithTTF("Welcome To iBreaker", "fonts/Marker Felt.ttf", 24);
	label->setColor(Color3B(0, 0, 0));
	// position the label on the center of the screen
	label->setPosition(Vec2(origin.x + visibleSize.width / 2,
		origin.y + visibleSize.height - label->getContentSize().height - 10));

	// add the label as a child to this layer
	this->addChild(label, 1);

	auto start_button = ui::Button::create("button_normal.png", "button_clicked.png", "button_disabled.png");

	auto start_label = Label::createWithTTF("START GAME", "fonts/Marker Felt.ttf", 24);
	start_label->setColor(Color3B(0, 0, 0));
	start_label->setPosition(Vec2(start_button->getLayoutSize().width / 2, start_button->getLayoutSize().height / 2));
	
	start_button->addChild(start_label);
	start_button->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 5 * 4 -50));
	start_button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type)
	{
		int n = 0;
		switch (type)
		{
			case ui::Widget::TouchEventType::BEGAN:
				break;
			case ui::Widget::TouchEventType::ENDED:
				n = 1;
				break;
			default:
				break;
		}
		if (n == 1)
		{
			auto director = Director::getInstance();
			auto scene = HelloWorld::createScene();
			// Transition Fade
			//director->replaceScene(TransitionFade::create(0.5, scene, Color3B(0, 255, 255)));
			// FlipX
			//director->replaceScene(TransitionFlipX::create(2, scene));

			// Transition Slide In
			director->replaceScene(TransitionSlideInT::create(1, scene));

			// run
			//director->replaceScene(scene);
		}
	});
	this->addChild(start_button, 1);

	
	auto quit_button = ui::Button::create("button_normal.png", "button_clicked.png", "button_disabled.png");

	auto quit_label = Label::createWithTTF("QUIT", "fonts/Marker Felt.ttf", 24);
	quit_label->setColor(Color3B(0, 0, 0));
	quit_label->setPosition(Vec2(quit_button->getLayoutSize().width / 2, quit_button->getLayoutSize().height / 2));
	
	quit_button->addChild(quit_label);
	quit_button->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 5 * 2 - 50));
	quit_button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type)
	{
		int n = 0;
		switch (type)
			{
			case ui::Widget::TouchEventType::BEGAN:
				break;
			case ui::Widget::TouchEventType::ENDED:
				n = 1;
				break;
			default:
				break;
		}
		if (n == 1)
		{
			Director::getInstance()->end();
		}
	});
	this->addChild(quit_button);

	
	drawBackground();
	
	return true;
}
Ejemplo n.º 19
0
void MainScene::nextScene(Ref* pSender){
	auto director = Director::getInstance();
	auto scene = StoryScene::createScene();
	director->replaceScene(TransitionFadeUp::create(0.5f, scene));
}
Ejemplo n.º 20
0
    virtual bool init() override
    {
        this->Layer::init();
        Resource::Load();

        auto director = cocos2d::Director::getInstance();
        auto visibleSize = director->getVisibleSize();
        auto background = cocos2d::Sprite::create(Resource::WELCOME_BACKGROUND);
        auto newGame = cocos2d::ui::Button::create(Resource::BUTTON_NEWGAME);
        auto logoMaples = cocos2d::Sprite::create(Resource::LOGO_MAPLE);

        this->player = Fighter::Create(cocos2d::Point(visibleSize.width * 0.2, visibleSize.height * 0.2));

        logoMaples->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.7));
        logoMaples->setBlendFunc(cocos2d::BlendFunc::ADDITIVE);

        background->setPosition(cocos2d::Point::ZERO);
        background->setAnchorPoint(cocos2d::Point::ZERO);

        newGame->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.5));
        newGame->addTouchEventListener([this, director](cocos2d::Ref * pSender, cocos2d::ui::Widget::TouchEventType type){
            if (type == cocos2d::ui::Widget::TouchEventType::ENDED)
            {

                auto stepOne = cocos2d::CallFunc::create([this]
                {
                    this->addChild(Effect::CreateFlare());
                });

                auto stepTwo = cocos2d::CallFunc::create([director]
                {
                    auto transition = cocos2d::TransitionFade::create(2.0, HelloWorld::createScene());
                    director->replaceScene(transition);
                });

                this->runAction(cocos2d::Sequence::create(stepOne, stepTwo, nullptr));

            }
        });

        auto moveToRight = cocos2d::MoveTo::create(2.0, cocos2d::Vec2(visibleSize.width * 0.2, visibleSize.height * 0.2));
        auto moveToLeft = cocos2d::MoveTo::create(2.0, cocos2d::Vec2(visibleSize.width * 0.8, visibleSize.height * 0.2));

        auto sequence = cocos2d::Sequence::create(moveToLeft, moveToRight, nullptr);
        auto playerAction = cocos2d::RepeatForever::create(sequence);

        this->player->runAction(playerAction);

        auto name = cocos2d::Label::create();
        name->setString("姓名 : 刘枫林 (Maples)");
        name->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.36));
        auto info = cocos2d::Label::create();
        info->setString("学号 : 2013060109005");
        info->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.3));

        this->addChild(background);
        this->addChild(this->player);
        this->addChild(logoMaples);
        this->addChild(newGame);
        this->addChild(name);
        this->addChild(info);


        this->scheduleUpdate();
        return true;
    }