Ejemplo n.º 1
0
bool QuitMenu::init()
{
	if (!Layer::init())
	{
		//auto label = Label::createWithSystemFont("Hello World", "Arial", 96);
		//label->setAnchorPoint(cocos2d::Vec2(0.0, 0.0));
		//this->addChild(label, 1);
		return false;
	}
	auto bg =
		Sprite::create("MainMenuScreen/BackgroundTemp.jpeg");
	auto areYouSureItem =
		MenuItemImage::create("QuitScreen/AreYouSureText.png",
		"QuitScreen/AreYouSureText.png");
	auto yesItem =
		MenuItemImage::create("QuitScreen/YesButton.png",
		"QuitScreen/YesButton.png",
		CC_CALLBACK_1(QuitMenu::menuCloseCallback, this));
	auto noItem =
		MenuItemImage::create("QuitScreen/NoButton.png",
		"QuitScreen/NoButton.png",
		CC_CALLBACK_1(QuitMenu::resume, this));
	Size visibleSize = Director::getInstance()->getVisibleSize();
	bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	bg->setScaleX(visibleSize.width / bg->getContentSize().width);
	bg->setScaleY(visibleSize.height / bg->getContentSize().height);
	auto menu = Menu::create(areYouSureItem, yesItem, noItem, NULL);
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 4);
	this->addChild(bg);
	this->addChild(menu);

	return true;
}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool MainMenuScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
	
	// Creating menu
	auto menuTitle = MenuItemImage::create("images/MainMenuScreen/Game_Title.png", "images/MainMenuScreen/Game_Title.png");
	auto playItem = MenuItemImage::create("images/MainMenuScreen/Play_Button.png", "images/MainMenuScreen/Play_Button(Click).png", CC_CALLBACK_1(MainMenuScene::goToGameScene, this));
	auto optionsItem = MenuItemImage::create("images/MainMenuScreen/Options_Button.png", "images/MainMenuScreen/Options_Button(Click).png", CC_CALLBACK_1(MainMenuScene::goToOptions, this));
	auto closeItem = MenuItemImage::create("images/MainMenuScreen/Close_Button.png", "images/MainMenuScreen/Close_Button(Click).png", CC_CALLBACK_1(MainMenuScene::goToClose, this));
	
	auto menu = Menu::create(menuTitle, playItem, optionsItem, closeItem, NULL);
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 8);
	addChild(menu, 1);
	
	auto background = Sprite::create("images/MainMenuScreen/Menu_Background.png");
	background->setPosition(Point((visibleSize.width / 2), (visibleSize.height / 2)));
	addChild(background, 0);

	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("audio/ButtonClick.wav");
	
	/*auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
	if (audio->isBackgroundMusicPlaying() == false) {
		audio->preloadBackgroundMusic("audio/Music.mp3");
		audio->playBackgroundMusic("audio/Music.mp3", true);
	}*/
    return true;
}
void HelloWorld::createTestMenu()
{
    sdkbox::PluginChartboost::setListener(this);
    sdkbox::PluginChartboost::cache(sdkbox::CB_Location_Default);
    sdkbox::PluginChartboost::cache(sdkbox::CB_Location_LevelComplete);
    
    MenuItemFont::setFontName("sans");
    Size size = Director::getInstance()->getWinSize();
    
    auto menu = Menu::create();
    menu->addChild(MenuItemLabel::create(Label::createWithSystemFont("video", "sans", 32), [](Ref*){
        CCLOG("sdkbox::PluginChartboost::show(sdkbox::CB_Location_Default);");
        sdkbox::PluginChartboost::show(sdkbox::CB_Location_Default);
    }));
    menu->addChild(MenuItemLabel::create(Label::createWithSystemFont("reward", "sans", 32), [](Ref*){
        CCLOG("sdkbox::PluginChartboost::show(sdkbox::CB_Location_LevelComplete);");
        sdkbox::PluginChartboost::show(sdkbox::CB_Location_LevelComplete);
    }));
    
    menu->alignItemsVerticallyWithPadding(15);
    menu->setPosition(Vec2(size.width / 2, size.height / 2));
    addChild(menu);
    
    _coin = 0;
    _coinLabel = Label::createWithSystemFont("0", "sans", 32);
    _coinLabel->setPosition(Vec2(size.width / 2, size.height - 80));
    addChild(_coinLabel);
}
// on "init" you need to initialize your instance
bool GameOver::init()
{

	if (!Layer::init())
	{
		return false;
	}

	auto menuTitle =
		MenuItemImage::create("GameOverScreen/Game_Over.png",
		"GameOverScreen/Game_Over.png");
	auto retryItem =
		MenuItemImage::create("GameOverScreen/Retry_Button.png",
		"GameOverScreen/Retry_Button(Click).png",
		CC_CALLBACK_1(GameOver::activateGameScene, this));
	auto mainMenuItem =
		MenuItemImage::create("GameOverScreen/Menu_Button.png",
		"GameOverScreen/Menu_Button(Click).png",
		CC_CALLBACK_1(GameOver::activateMainMenuScene, this));
	auto menu = Menu::create(menuTitle, retryItem, mainMenuItem,
		NULL);

	Size visibleSize = Director::getInstance()->getVisibleSize();
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 4);
	this->addChild(menu);

    return true;
}
Ejemplo n.º 5
0
bool MainMenuScene::init() {
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size winSize = Director::getInstance()->getWinSize();
    
    auto menuLabel1 = LabelTTF::create("ColorMatrix", "Arial", 24);
    auto menuItem1 = MenuItemLabel::create(menuLabel1, [] (Ref*) {
        auto scene = CCColorMatrixFunctionalTestScene::scene();
        Director::getInstance()->replaceScene(scene);
    });
    
    auto menuLabel2 = LabelTTF::create("TextureTransform", "Arial", 24);
    auto menuItem2 = MenuItemLabel::create(menuLabel2, [] (Ref*) {
        auto scene = CCTextureTransformFunctionalTestScene::scene();
        Director::getInstance()->replaceScene(scene);
    });
    
    auto menu = Menu::create(menuItem1, menuItem2, nullptr);
    menu->alignItemsVerticallyWithPadding(125);
    menu->setPosition(Point(winSize.width / 2, winSize.height / 2));
    this->addChild(menu);
    
    return true;
}
Ejemplo n.º 6
0
bool GameMenu::init()
{
    if (!Layer::init()) {
        return false;
    }
    
    Size size = Director::getInstance()->getWinSize();
    LayerColor *layerColor = LayerColor::create(Color4B(223, 253, 253, 255), size.width, size.height);
    this->addChild(layerColor);
    
//    Label *label = Label::createWithBMFont("fonts.fnt", "Miku Run");
//    label->setScale(0.7);
//    label->setPosition(Point(130, size.height-50));
//    this->addChild(label);
    
    MenuItemImage *startItem = MenuItemImage::create("bird_start_btn.png", "brid_start_btn_pressed.png",CC_CALLBACK_1(GameMenu::startGame, this));
    startItem->setScale(1.5);
    
    auto menu = Menu::create(startItem,NULL);
    menu->alignItemsVerticallyWithPadding(20);
    //menu->alignItemsHorizontallyWithPadding(50);
    menu->setPosition(Point(160,size.height/2));
    this->addChild(menu, 1);
    
    return true;
}
Ejemplo n.º 7
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{

	if (!LayerColor::initWithColor(Color4B(255, 255, 255, 255)))
	{
		return false;
	}

	/////////////////////////////
	auto pMenItem1 = MenuItemFont::create("do Show",
		CC_CALLBACK_1(HelloWorld::doShow, this));
	pMenItem1->setColor(Color3B(0, 0, 0));

	auto pMenItem2 = MenuItemFont::create("do Hide",
		CC_CALLBACK_1(HelloWorld::doHide, this));
	pMenItem2->setColor(Color3B(0, 0, 0));

	auto pMenItem3 = MenuItemFont::create("do FullShow",
		CC_CALLBACK_1(HelloWorld::doFullShow, this));
	pMenItem3->setColor(Color3B(0, 0, 0));

	auto menu = Menu::create(pMenItem1, pMenItem2, pMenItem3, nullptr);
	menu->alignItemsVerticallyWithPadding(10.0f);
	this->addChild(menu);

	////////////////////

	g_pHello = this;

	///////////////////
	return true;
}
Ejemplo n.º 8
0
bool SelectLevel::init() {
	if (!Layer::init())
	{
		return false;
	}

	dispatcher = Director::getInstance()->getEventDispatcher();
	winSize = Director::getInstance()->getWinSize();

	Sprite* background = Sprite::create("StartScene.png");
	background->setPosition(winSize / 2);
	addChild(background);

	auto item1 = MenuItemLabel::create(Label::createWithSystemFont("初级", "Microsoft Yahei", 30.0f), CC_CALLBACK_1(SelectLevel::start, this, 0));
	auto item2 = MenuItemLabel::create(Label::createWithSystemFont("中级", "Microsoft Yahei", 30.0f), CC_CALLBACK_1(SelectLevel::start, this, 1));
	auto item3 = MenuItemLabel::create(Label::createWithSystemFont("高级", "Microsoft Yahei", 30.0f), CC_CALLBACK_1(SelectLevel::start, this, 2));

	// create menu, it's an autorelease object
	auto menu = Menu::create(item1, item2, item3, NULL);
	menu->setPosition(winSize.width / 2, winSize.height / 2);
	menu->alignItemsVerticallyWithPadding(item1->getContentSize().height / 2);
	this->addChild(menu, 1);

	return true;
}
void MainScene::onResult(){
    _gameState = GameState::RESULT;
    auto winSize = Director::getInstance()->getWinSize();
    
    auto replayButton =
        MenuItemImage::create("replay_button.png",
                              "replay_button_pressed.png",
                              [](Ref* ref){
                                  auto scene = MainScene::createScene();
                                  auto transition = TransitionFade::create(0.5, scene);
                                  Director::getInstance()->replaceScene(transition);
                              });
    auto titleButton =
        MenuItemImage::create("title_button.png",
                              "title_button_pressed.png",
                              [](Ref* ref){
                                  auto scene = TitleScene::createScene();
                                  auto transition = TransitionFade::create(0.5, scene);
                                  Director::getInstance()->replaceScene(transition);
                              });
    auto menu = Menu::create(replayButton, titleButton, NULL);
    menu->alignItemsVerticallyWithPadding(15);
    menu->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
    this->addChild(menu);
}
Ejemplo n.º 10
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
	auto label1=Label::createWithBMFont("fonts/fnt8.fnt","init plist");
	auto label2=Label::createWithBMFont("fonts/fnt8.fnt","Insert Data");
	auto label3=Label::createWithBMFont("fonts/fnt8.fnt","Delete Data");
	auto label4=Label::createWithBMFont("fonts/fnt8.fnt","Read data");

	auto mnItem1=MenuItemLabel::create(label1,CC_CALLBACK_1(HelloWorld::menuCloseCallback1,this));
	auto mnItem2=MenuItemLabel::create(label2,CC_CALLBACK_1(HelloWorld::menuCloseCallback2,this));
	auto mnItem3=MenuItemLabel::create(label3,CC_CALLBACK_1(HelloWorld::menuCloseCallback3,this));
	auto mnItem4=MenuItemLabel::create(label4,CC_CALLBACK_1(HelloWorld::menuCloseCallback4,this));
	auto menu=Menu::create(mnItem1,mnItem2,mnItem3,mnItem4,NULL);
	menu->alignItemsVerticallyWithPadding(40);
	addChild(menu);
	return true;
}
Ejemplo n.º 11
0
bool SubMenuScreen::init()
{
    if (!Layer::init()) {
        return false;
    }
    bool bRet = false;
    do {
        Size visibleSize = Director::getInstance()->getVisibleSize();
        //background
        auto bg = Sprite::create("start1.jpg");
        CC_BREAK_IF(! bg);
        bg->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
        this->addChild(bg);
        
        //menu item
        auto challengeItem = MenuItemImage::create("chalenge.png", "chalenge_press.png", CC_CALLBACK_1(SubMenuScreen::onButtonCallback, this));
        challengeItem->setTag(CHALLENGE_BTN);
        auto renshyuItem = MenuItemImage::create("exercise1.png", "exercise1_press.png", CC_CALLBACK_1(SubMenuScreen::onButtonCallback, this));
        renshyuItem->setTag(RENSHYU_BTN);
        
        auto menu1 = Menu::create(challengeItem, renshyuItem, NULL);
        menu1->alignItemsVerticallyWithPadding(20);
        menu1->setPosition(Point(visibleSize.width/2, 2*visibleSize.height/3 - 130));
        CC_BREAK_IF(!menu1);
        this->addChild(menu1);
        bRet = true;
    } while (0);
    
    
    return bRet;
}
Ejemplo n.º 12
0
// on "init" you need to initialize your instance
bool Acerca::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	//Cargamos los elementos visuales del menu del juego
	auto menuTitle = MenuItemImage::create("images/MainMenuScreen/Game_Title.png", "images/MainMenuScreen/Game_Title.png");

	auto volverMenuPrincipal = MenuItemImage::create("images/volver.fw.png","images/MainMenuScreen/Play_Button(Click).png",
		CC_CALLBACK_1(Acerca::ir_Menu_Principal, this));

	auto menu = Menu::create(menuTitle, volverMenuPrincipal, NULL);
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 12);
	addChild(menu, 1);


	//Modificacion de la imagen de fondo de la escena, en la pantalla de menu
	auto background = Sprite::create("images/PantallaMinijuegos.png");
	background->setPosition(Point((visibleSize.width / 2),(visibleSize.height / 2)));
	addChild(background, 0);
	//Fin de la modificación del tutorial
	return true;
}
Ejemplo n.º 13
0
// on "init" you need to initialize your instance
bool PauseMenuScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

   auto resumeItem = MenuItemImage::create("PauseScreen/Resume_Button.png", 
	   "PauseScreen/Resume_Button(Click).png", 
	   CC_CALLBACK_1(PauseMenuScene::Resume, this));

   auto retryItem = MenuItemImage::create("PauseScreen/Retry_Button.png", 
	  "PauseScreen/Retry_Button(Click).png", 
	   CC_CALLBACK_1(PauseMenuScene::Retry, this));


   auto mainMenu = MenuItemImage::create("PauseScreen/Menu_Button.png", 
	   "PauseScreen/Menu_Button(Click).png", 
	   CC_CALLBACK_1(PauseMenuScene::GoToMainMenuScene, this));

   auto menu = Menu::create( resumeItem, retryItem, mainMenu, NULL );
   menu->alignItemsVerticallyWithPadding(visibleSize.height /4 );
   this->addChild( menu );


    return true;
}
Ejemplo n.º 14
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{

	if (!LayerColor::initWithColor(Color4B(255, 255, 255, 255)))
	{
		return false;
	}

	/////////////////////////////
	auto pMenItem1 = MenuItemFont::create("Add Sprite",
		CC_CALLBACK_1(HelloWorld::addSprite, this));
	pMenItem1->setColor(Color3B(0, 0, 0));

	auto pMenItem2 = MenuItemFont::create("Remove Sprite",
		CC_CALLBACK_1(HelloWorld::removeSprite, this));
	pMenItem2->setColor(Color3B(0, 0, 0));

	auto menu = Menu::create(pMenItem1, pMenItem2, nullptr);
	menu->alignItemsVerticallyWithPadding(50.0f);
	this->addChild(menu);

	////////////////////

	g_pHello = this;

	///////////////////

	addSpriteFromJava();
	return true;
}
Ejemplo n.º 15
0
// on "init" you need to initialize your instance
bool PauseScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
   
	auto resumeItem = MenuItemImage::create("images/PauseScreen/Resume_Button.png", "images/PauseScreen/Resume_Button(Click).png", 
		CC_CALLBACK_1(PauseScene::resumeGameScene, this));

	auto replayItem = MenuItemImage::create("images/PauseScreen/Retry_Button.png", "images/PauseScreen/Retry_Button(Click).png",
		CC_CALLBACK_1(PauseScene::retryGameScene, this));

	auto menuItem = MenuItemImage::create("images/PauseScreen/Menu_Button.png", "images/PauseScreen/Menu_Button(Click).png",
		CC_CALLBACK_1(PauseScene::goToMainMenu, this));

	auto menu = Menu::create(resumeItem, replayItem, menuItem, NULL);
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 10);
	addChild(menu, 1);

	auto background = Sprite::create("images/PauseScreen/Pause_Background.png");
	background->setPosition(visibleSize.height / 2, visibleSize.width / 2);
	addChild(background, 0);

    return true;
}
Ejemplo n.º 16
0
// on "init" you need to initialize your instance
bool PauseScene::init()
{
	//////////////////////////////GameScreen
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}
	
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	//Cursor
	_cursorSprite = Sprite::create("cursor1.png");
	addChild(_cursorSprite, 7);
	_cursorSprite->setVisible(false);

	_cursorSprite2 = Sprite::create("cursor2.png");
	addChild(_cursorSprite2, 6);

	auto resumeItem = MenuItemImage::create("reanudar.png", "reanudar.png",
		CC_CALLBACK_1(PauseScene::resumeGameScreen,
			this));

	auto closeItem = MenuItemImage::create("medicine1.png", "medicine1.png",
		CC_CALLBACK_1(PauseScene::menuCloseCallback, this));

	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
		origin.y + closeItem->getContentSize().height / 2));

	auto menu = Menu::create(resumeItem, closeItem, NULL);

	menu->alignItemsVerticallyWithPadding(visibleSize.height / 4);
	addChild(menu, 1);

	if (TutorialPantalla == 0) {
		auto background = Sprite::create("PausaWebster.png");
		background->setPosition(Point((visibleSize.width / 2),
			(visibleSize.height / 2)));
		addChild(background, 0);
	}
	if(TutorialPantalla == 1)
	{
		auto background = Sprite::create("PausaNina2.png");
		background->setPosition(Point((visibleSize.width / 2),
			(visibleSize.height / 2)));
		addChild(background, 0);
	}

	auto mouseListener = EventListenerMouse::create();
	mouseListener->onMouseMove = CC_CALLBACK_1(PauseScene::onMouseMove, this);
	this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseListener, this);

	return true;
}
Ejemplo n.º 17
0
bool PauseLevel2::init()
{
	if (!Layer::init())
	{
		return false;
	}

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

	auto backgroundSprite = Sprite::create("GameOverScreen/background.png");
	backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(backgroundSprite);

	auto menuTitle =
		Sprite::create("PauseScreen/Pauselogo.png");
	menuTitle->setPosition(Point(visibleSize.width / 2, (visibleSize.height - 40)));
	this->addChild(menuTitle);

	auto resumeItem =
		MenuItemImage::create("PauseScreen/resumebutton.png",
			"PauseScreen/resumebutton.png",
			CC_CALLBACK_1(PauseLevel2::resume, this));
	auto retryItem =
		MenuItemImage::create("PauseScreen/retrybutton.png",
			"PauseScreen/retrybutton.png",
			CC_CALLBACK_1(PauseLevel2::retry, this));
	auto musicItem =
		MenuItemImage::create("PauseScreen/musicbutton.png",
			"PauseScreen/musicbutton.png",
			CC_CALLBACK_1(PauseLevel2::ToggleMusic, this));
	auto mainMenuItem =
		MenuItemImage::create("PauseScreen/mainmenubutton.png",
			"PauseScreen/mainmenubutton.png",
			CC_CALLBACK_1(PauseLevel2::activateMainMenuScene, this));
	auto menu = Menu::create(resumeItem, retryItem, musicItem, mainMenuItem,
		NULL);
	
	//scales all the buttons in the scene
	resumeItem->setScale(1.25f);
	retryItem->setScale(1.25f);
	musicItem->setScale(1.25f);
	mainMenuItem->setScale(1.25f);

	menu->alignItemsVerticallyWithPadding(visibleSize.height / 35);
	menu->setPosition(Point(visibleSize.width / 2, (visibleSize.height - 245)));
	this->addChild(menu);

	return true;
}
Ejemplo n.º 18
0
//ゲームオーバー時に呼び出される
void MainScene::onGameOver()
{
    //状態をゲームオーバーにし、プレイヤーを取り除く
    this->setState(State::GAMEOVER);
    _stage->getPlayer()->removeFromParent();

    //ウィンドウサイズを取り出し
    auto winSize = Director::getInstance()->getWinSize();

    //ステージレベルを取り出し
    int currentStage = _stage->getLevel();

    //コイン枚数を初期化
    UserDefault *_userDef = UserDefault::getInstance();
    _userDef->setIntegerForKey("current_score",0);

    //時間を初期化
    _userDef->setIntegerForKey("current_time",0);


    //ゲームオーバーロゴを表示
    auto gameover = Sprite::create("gameover.png");
    gameover->setPosition(Vec2(winSize.width / 2.0, winSize.height / 1.5));
    this->addChild(gameover);

    auto menuItem = MenuItemImage::create("replay.png", "replay_pressed.png", [currentStage](Ref *sender) {
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(AudioUtils::getFileName("decide").c_str());
        auto scene = MainScene::createSceneWithStage(0);
        auto transition = TransitionFade::create(1.0, scene);
        Director::getInstance()->replaceScene(transition);
    });
    auto returnTitle = MenuItemImage::create("return.png", "return_pressed.png", [](Ref *sender) {
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(AudioUtils::getFileName("decide").c_str());
        auto scene = TitleScene::createScene();
        auto transition = TransitionFade::create(1.0, scene);
        Director::getInstance()->replaceScene(transition);
    });
    auto menu = Menu::create(menuItem, returnTitle, nullptr);
    menu->alignItemsVerticallyWithPadding(20);
    this->addChild(menu);
    menu->setPosition(winSize.width / 2.0, winSize.height / 3);

    // パーティクル表示
    auto explosition = ParticleExplosion::create();
    explosition->setPosition(_stage->getPlayer()->getPosition());
    _stage->addChild(explosition);


    //音楽を止める:CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
    //CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(AudioUtils::getFileName("explode").c_str());
}
Ejemplo n.º 19
0
bool GameOverScene::init()
{
	if (!Scene::init()){
		return false;
	}


	Vector<MenuItem*> MenuItems;

	auto myMenu = Menu::create();
	TTFConfig labelConfig;
	labelConfig.fontFilePath = "fonts/Marker Felt.ttf";
	labelConfig.fontSize = 48;
	labelConfig.glyphs = GlyphCollection::DYNAMIC;
	labelConfig.outlineSize = 2;
	labelConfig.customGlyphs = nullptr;
	labelConfig.distanceFieldEnabled = false;


	auto gameoverItem = MenuItemLabel::create(Label::createWithTTF(labelConfig, "GAME OVER"));
	gameoverItem->setColor(Color3B(255, 255, 255));
	MenuItems.pushBack(gameoverItem);
	
	auto scorelabel = Label::createWithTTF(labelConfig, "");
	auto scoreItem = MenuItemLabel::create(scorelabel);
	scoreItem->setTag(TAG_SCORE_TEXT);
	scoreItem->setColor(Color3B(255, 255, 255));
	MenuItems.pushBack(scoreItem);

	auto playItem = MenuItemLabel::create(Label::createWithTTF(labelConfig, "Play again"),
		[&](Ref* sender){
		this->transitionToGameScene();
	});
	playItem->setColor(Color3B(255, 255, 0));
	MenuItems.pushBack(playItem);

	auto closeItem = MenuItemLabel::create(Label::createWithTTF(labelConfig, "Quit"),
		[&](Ref* sender){
		this->quit();
	});
	closeItem->setColor(Color3B(255, 255, 0));
	MenuItems.pushBack(closeItem);


	auto menu = Menu::createWithArray(MenuItems);
	menu->setTag(TAG_MENU);
	menu->alignItemsVerticallyWithPadding(50.0f);
	this->addChild(menu, 1);

	return true;
}
Ejemplo n.º 20
0
//------------------------------------------------------------------
//
// LabelTTFTest
//
//------------------------------------------------------------------
LabelTTFTest::LabelTTFTest()
{
    auto blockSize = Size(200, 160);
    auto s = Director::getInstance()->getWinSize();

    auto colorLayer = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
    colorLayer->setAnchorPoint(Point(0,0));
    colorLayer->setPosition(Point((s.width - blockSize.width) / 2, (s.height - blockSize.height) / 2));

    this->addChild(colorLayer);

    MenuItemFont::setFontSize(30);
    auto menu = Menu::create(
		MenuItemFont::create("Left", CC_CALLBACK_1(LabelTTFTest::setAlignmentLeft, this)),
		MenuItemFont::create("Center", CC_CALLBACK_1(LabelTTFTest::setAlignmentCenter, this)),
		MenuItemFont::create("Right", CC_CALLBACK_1(LabelTTFTest::setAlignmentRight, this)),
        NULL);
    menu->alignItemsVerticallyWithPadding(4);
    menu->setPosition(Point(50, s.height / 2 - 20));
    this->addChild(menu);

    menu = Menu::create(
		MenuItemFont::create("Top", CC_CALLBACK_1(LabelTTFTest::setAlignmentTop, this)),
		MenuItemFont::create("Middle", CC_CALLBACK_1(LabelTTFTest::setAlignmentMiddle, this)),
		MenuItemFont::create("Bottom", CC_CALLBACK_1(LabelTTFTest::setAlignmentBottom, this)),
		NULL);
    menu->alignItemsVerticallyWithPadding(4);
    menu->setPosition(Point(s.width - 50, s.height / 2 - 20));
    this->addChild(menu);

    _plabel = NULL;
    _horizAlign = TextHAlignment::LEFT;
    _vertAlign = TextVAlignment::TOP;

    this->updateAlignment();
}
Ejemplo n.º 21
0
void CouponListScene::createCouponList() {
	// first, read values from user data
	auto typeOne = UserDefault::getInstance()->getIntegerForKey(Coupon::TYPE_ONE.c_str());
	auto typeOneUsed = UserDefault::getInstance()->getIntegerForKey(Coupon::TYPE_ONE_USED.c_str());
	auto typeTwo = UserDefault::getInstance()->getIntegerForKey(Coupon::TYPE_TWO.c_str());
	auto typeTwoUsed = UserDefault::getInstance()->getIntegerForKey(Coupon::TYPE_TWO_USED.c_str());
	
	auto screenSize = Director::getInstance()->getWinSize();

	Vector<MenuItem*> coupons;

	// create the unused ones first
	for (auto i = typeOneUsed; i < typeOne; i++) {
		auto couponItem = createCouponMenuItem(
			screenSize, Coupon::TYPE_ONE_TEXT, false, CC_CALLBACK_1(CouponListScene::unusedCouponOne, this)
		);
		coupons.pushBack(couponItem);
	}
	for (auto i = typeTwoUsed; i < typeTwo; i++) {
		auto couponItem = createCouponMenuItem(
			screenSize, Coupon::TYPE_TWO_TEXT, false, CC_CALLBACK_1(CouponListScene::unusedCouponTwo, this)
		);
		coupons.pushBack(couponItem);
	}

	// then the used ones
	for (auto i = 0; i < typeOneUsed; i++) {
		auto couponItem = createCouponMenuItem(
			screenSize, Coupon::TYPE_ONE_TEXT, true, CC_CALLBACK_1(CouponListScene::usedCouponOne, this)
		);
		coupons.pushBack(couponItem);
		_usedCoupons.pushBack(couponItem);
	}
	for (auto i = 0; i < typeTwoUsed; i++) {
		auto couponItem = createCouponMenuItem(
			screenSize, Coupon::TYPE_TWO_TEXT, true, CC_CALLBACK_1(CouponListScene::usedCouponTwo, this)
		);
		coupons.pushBack(couponItem);
		_usedCoupons.pushBack(couponItem);
	}

	// now create the menu
	auto menu = Menu::createWithArray(coupons);
	addChild(menu);
	menu->setAnchorPoint(Vec2(0.5f, 1.0f));
	menu->setPosition(screenSize.width * 0.5f, screenSize.height * 0.4f);
	menu->alignItemsVerticallyWithPadding(screenSize.height * 0.05f);
}
Ejemplo n.º 22
0
void TitleScene::makeButtons()
{
	Size visibleSize = Director::getInstance()->getVisibleSize();

	auto startItem = MenuItemImage::create(
		"StartButton.png","StartButtonPressed.png", 
		CC_CALLBACK_1(TitleScene::menuStartCallback, this));
	auto closeItem = MenuItemImage::create(
		"ExitButton.png","ExitButtonPressed.png",
		CC_CALLBACK_1(TitleScene::menuCloseCallback, this));

	auto menu = Menu::create(startItem, closeItem, NULL);
	menu->alignItemsVerticallyWithPadding(30.f);
	menu->setPosition(visibleSize.width/2, visibleSize.height/2 - 150.f);
	this->addChild(menu, 1);
}
Ejemplo n.º 23
0
void HelloWorld::createGameMenu()
{
    auto levels = MenuItemLabel::create(
                Label::createWithTTF("Niveles",font,60),
                CC_CALLBACK_1(HelloWorld::showLevels, this));
    auto achievements = MenuItemLabel::create(
                Label::createWithTTF("Logros",font,60),
                CC_CALLBACK_1(HelloWorld::showAchivements, this));
    auto credits = MenuItemLabel::create(
                Label::createWithTTF("Creditos",font,60),
                CC_CALLBACK_1(HelloWorld::showCredits, this));

    auto menu = Menu::create(levels,achievements,credits, NULL);
    menu->alignItemsVerticallyWithPadding(10);
    menu->setPosition(Point(visibleSize.width/4,visibleSize.height/2));
    this->addChild(menu, 1);
}
Ejemplo n.º 24
0
bool MainMenuLayer::init()
{
    if(!Layer::init())
    {
        return false;
    }
    
	MenuItemFont::setFontName("fonts/arial.ttf");
	MenuItemFont::setFontSize(40);

	auto menuItemSelectMap = MenuItemFont::create(std::string(LocalizedCStringByKey("start_game")));
	menuItemSelectMap->setCallback(
		[=](Ref*)
	{

		static_cast<LayerMultiplex*>(_parent)->switchTo(1);
	}
		);


	auto menuItemMapMaker = MenuItemFont::create(std::string(LocalizedCStringByKey("map_maker")));
	menuItemMapMaker->setCallback(
		[](Ref*)
	{
		auto scene = Scene::create();
		scene->addChild(MapMakerScene::create());
		Director::getInstance()->replaceScene(TransitionFlipX::create(0.5, scene));

	}
	);


	auto menu = Menu::create(menuItemSelectMap, menuItemMapMaker, nullptr);
	menu->alignItemsVerticallyWithPadding(20);

	auto s = Director::getInstance()->getWinSize();
	addChild(menu);
	menu->setPosition(Vec2(s.width / 2, s.height / 2));
	


    return true;
}
Ejemplo n.º 25
0
bool pauseScene::init()
{
	if (!LayerColor::initWithColor(Color4B(0, 0, 0, 200)))
	{
		return false;
	}

	auto winSize = Director::getInstance()->getWinSize();

	/*auto popLayer = CCLayerColor::create(Color4B(0, 0, 0, 100), 600, 400);
	popLayer->setAnchorPoint(Vec2(0, 0));
	popLayer->setPosition(Vec2((winSize.width - popLayer->getContentSize().width) / 2, (winSize.height - popLayer->getContentSize().height) / 2));

	this->addChild(popLayer);*/

	//MenuItemFont::setFontSize(14.0f);
	
	auto pMenuItem1 = MenuItemImage::create("Images/Scene/pause_button11.png", "Images/Scene/pause_button1.png", CC_CALLBACK_1(pauseScene::doContinue, this));
	//pMenuItem1->setPosition(Vec2(100, 660));
	pMenuItem1->setScale(2);
	pMenuItem1->setTag(1);
	auto pMenuItem2 = MenuItemImage::create("Images/Scene/pause_button21.png", "Images/Scene/pause_button2.png", CC_CALLBACK_1(pauseScene::doClose, this));
	//pMenuItem2->setPosition(Vec2(1200, 650));
	pMenuItem2->setScale(2);
	pMenuItem2->setTag(2);
	//auto pMenuItem3 = MenuItemImage::create("Images/Scene/pause_button31.png", "Images/Scene/pause_button3.png", CC_CALLBACK_1(pauseScene::doSendMsg, this));
	//pMenuItem3->setPosition(Vec2(1200, 650));
	//pMenuItem3->setScale(2);
	//pMenuItem3->setTag(3);
	auto pMenu = Menu::create(pMenuItem1, pMenuItem2, nullptr);
	pMenu->alignItemsVerticallyWithPadding(20.0f);
	pMenu->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
	this->addChild(pMenu, 4);



	std::string str1 = "0";
	char str2[20] = { 0 };
	sprintf(str2, "%s", str1.c_str());
	NotificationCenter::getInstance()->postNotification("TouchStatus", (Ref*)str2);

	return true;
}
Ejemplo n.º 26
0
LabelTTFDynamicAlignment::LabelTTFDynamicAlignment()
{
    auto size = Director::getInstance()->getWinSize();
    TTFConfig ttfConfig("fonts/arial.ttf", 45);
    _label = Label::createWithTTF(ttfConfig,LongSentencesExample, TextHAlignment::CENTER, size.width);
    _label->setPosition( Point(size.width/2, size.height/2) );
    _label->setAnchorPoint(Point::ANCHOR_MIDDLE);  
    
    auto menu = Menu::create(
                              MenuItemFont::create("Left", CC_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentLeft, this)),
                              MenuItemFont::create("Center", CC_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentCenter, this)),
                              MenuItemFont::create("Right", CC_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentRight, this)),
                              NULL);
    
    menu->alignItemsVerticallyWithPadding(4);
    menu->setPosition(Point(50, size.height / 4 ));
    
    addChild(_label);
    this->addChild(menu);
}
bool TutorialOver::init()
{
	if (!Layer::init())
	{
		return false;
	}

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

	auto backgroundSprite = Sprite::create("GameOverScreen/background.png");
	backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(backgroundSprite);

	auto menuTitle =
		Sprite::create("Tutorial/completedHeader.png");
	menuTitle->setPosition(Point(visibleSize.width / 2, (visibleSize.height - 32)));
	menuTitle->setScale(1.35f);
	this->addChild(menuTitle);

	auto retryItem =
		MenuItemImage::create("MainMenuScreen/playbutton.png",
			"MainMenuScreen/playbutton.png",
			CC_CALLBACK_1(TutorialOver::activateGameScene, this));
	auto mainMenuItem =
		MenuItemImage::create("GameOverScreen/mainmenubutton.png",
			"GameOverScreen/mainmenubutton.png",
			CC_CALLBACK_1(TutorialOver::activateMainMenuScene, this));
	auto menu = Menu::create(retryItem, mainMenuItem,
		NULL);
	retryItem->setScale(1.18f);
	mainMenuItem->setScale(1.18f);
	menu->alignItemsVerticallyWithPadding(visibleSize.height / 15);
	menu->setPosition(Point(visibleSize.width / 2, (visibleSize.height - 235)));
	this->addChild(menu);

	return true;
}
Ejemplo n.º 28
0
void MenuLayer2::alignMenusV()
{
    for(int i=0;i<2;i++) 
    {
        auto menu = static_cast<Menu*>( getChildByTag(100+i) );
        menu->setPosition( _centeredMenu );
        if(i==0) 
        {
            // TIP: if no padding, padding = 5
            menu->alignItemsVertically();            
            auto p = menu->getPosition();
            menu->setPosition(p + Vec2(100,0));
        } 
        else 
        {
            // TIP: but padding is configurable
            menu->alignItemsVerticallyWithPadding(40);    
            auto p = menu->getPosition();
            menu->setPosition(p - Vec2(100,0));
        }        
    }
}
Ejemplo n.º 29
0
bool MainMenuLayer::init()
{
    if( !CCLayerColor::initWithColor(Color4B(255, 255, 255, 255)) )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto playbuttonItem = MenuItemImage::create("button_play.png", "button_play.png", CC_CALLBACK_1(MainMenuLayer::onMenuPlayButton, this));
    auto tutorialbuttonItem = MenuItemImage::create("button_tutorial.png", "button_tutorial.png", CC_CALLBACK_1(MainMenuLayer::onMenuTutorialButton, this));
    auto menubuttonItem = MenuItemImage::create("button_menu.png", "button_menu.png", CC_CALLBACK_1(MainMenuLayer::onMenuMenuButton, this));
	

    auto menu = Menu::create(playbuttonItem, tutorialbuttonItem, menubuttonItem, NULL);
    menu->alignItemsVerticallyWithPadding(20);
    menu->setPosition(Vec2(origin.x + visibleSize.width/2,
                           origin.y + visibleSize.height/2 - playbuttonItem->getContentSize().height/2));
    this->addChild(menu, 1);
    
    return true;
}
Ejemplo n.º 30
0
Menu* MyMenu::CreateMenu()
{
	//create menu
	auto MenuItem_Game = MenuItemFont::create("Start Game");
	MenuItem_Game->setCallback([&](Ref *sender) {
		Director::getInstance()->replaceScene(TransitionFlipX::create(1, BlueScene::createScene()));
	});
	auto MenuItem_About = MenuItemFont::create("About");
	MenuItem_About->setCallback([&](Ref *sender) {
		//Director::getInstance()->replaceScene(TransitionFlipX::create(1, AboutScene::createScene()));
	});
	auto MenuItem_Exit = MenuItemFont::create("Exit");
	MenuItem_Exit->setCallback([&](Ref *sender) {
		menuCloseCallback(sender);
	});

	Vector<MenuItem*> items;
	items.pushBack(MenuItem_Game); items.pushBack(MenuItem_About); items.pushBack(MenuItem_Exit);

	auto menu = Menu::createWithArray(items);
	menu->alignItemsVerticallyWithPadding(20);

	return menu;
}