Example #1
0
// on "init" you need to initialize your instance
bool GameScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Scene::init() )
    {
        return false;
    }
    
    instance = this;
    
    listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    _size = Director::getInstance()->getWinSize();
    
    
    addBackGround();
    
    play = PlayLayer::create();
    this->addChild(play);
    
    
    return true;
}
Example #2
0
bool CupcakeTitle::init(){
    
    if (!Layer::init()) {
        return false;
    }
    
    
    auto winSize = Director::getInstance()->getWinSize();
    
    auto tools = Tools::create();
    tools->addTouchEff(this);
    tools->addBackGround(this);
    
    auto titleFrame = Sprite::create("CupcakeFrame.png");
    titleFrame->setScale(0.8, 0.6);
    titleFrame->setPosition(Vec2(winSize.width / 2.0, winSize.height / 1.7));
    this->addChild(titleFrame);
    
    
    auto titleLabel = tools->blueLabel("カップケーキを作ろう!", 70,true);
    
    auto titleButton = MenuItemLabel::create(titleLabel,
                                             [&](Ref* ref){
                                                 
                                                 auto label = static_cast<MenuItemLabel*>(ref);
                                                 label->setString("Making Cupcakes");
                                                 label->setScale(1.5);
                                                 
                                                 tools->playSound(Tools::sound::P0);
                                             });
    
    auto titleLabelMenu = Menu::create(titleButton,NULL);
    titleLabelMenu->setPosition(Vec2(winSize.width / 2.0, winSize.height / 1.7));
    this->addChild(titleLabelMenu, 2);

    
    auto start = MenuItemImage::create("CupcakeStart.png","CupcakeStartPress.png",
                                       [&](Ref* ref){
                                           auto scene = Page1::createScene();
                                           tools->playSound(Tools::sound::TAP1);
                                           auto transition = TransitionPageTurn::create(1.5, scene,false);
                                           Director::getInstance()->replaceScene(transition);
                                           
    });
    
    
    auto menu = Menu::create(start, NULL);
    
    
    menu->setPosition(Vec2(winSize.width / 2, winSize.height / 4));
    
    this->addChild(menu);
    
    
    return true;
}
Example #3
0
bool Page4::init(){
    
    if (!Layer::init()) {
        return false;
    }
    
    
    auto tools = Tools::create();
    
    auto winSize = Director::getInstance()->getWinSize();
    
    tools->addTouchEff(this);
    tools->addBackGround(this);
    tools->addTitleFrame(this);
    
    
    auto titleLabel = tools->blueLabel("こむぎことふくらしこをふるって入れよう", 28,true);
    
    auto titleButton = MenuItemLabel::create(titleLabel,
                                             [&](Ref* ref){
                                                 
                                                 auto label = static_cast<MenuItemLabel*>(ref);
                                                 label->setString("Sift the flour and baking powder");
                                                 label->setScale(1.3);
                                                 
                                                 tools->playSound(Tools::sound::P4);
                                             });
    
    auto titleLabelMenu = Menu::create(titleButton,NULL);
    titleLabelMenu->setPosition(Vec2(winSize.width / 2.0, winSize.height / 1.1));
    this->addChild(titleLabelMenu, 2);
    
    
    auto actPhoto = Sprite::create("CupcakeMake3.png");
    actPhoto->setTag(10);
    actPhoto->setOpacity(0);
    actPhoto->setScale(1.3);
    actPhoto->setPosition(Vec2(winSize.width / 2, winSize.height / 2.2));
    this->addChild(actPhoto);
    
    
    
    auto photo = MenuItemImage::create("CupcakeMake3.png","CupcakeMake3.png",
                                       [&](Ref* ref){
                                           
                                           auto myImg = static_cast<MenuItemImage*>(ref);
                                           myImg->setOpacity(0);
                                           
                                           auto actImg = static_cast<Sprite*>(getChildByTag(10));
                                           actImg->setOpacity(255);
                                           actImg->runAction(RotateBy::create(0.2, 0, 180));
                                           
                                           tools->playSoundSet(_tapNum, "C");
                                           
                                           if(_tapNum > 2){
                                               _tapNum = 0;
                                           }else{
                                               _tapNum++;
                                           }

                                           
                                       });
    
    photo->setScale(1.3);
    photo->setPosition(Vec2(winSize.width / 2, winSize.height / 2.2));
    
    auto photoMenu = Menu::create(photo, NULL);
    photoMenu->setPosition(0, 0);
    this->addChild(photoMenu);
    
    
    
    auto next = MenuItemImage::create("CupcakeNext.png","CupcakeNextPress.png",
                                      [&](Ref* ref){
                                          tools->playSound(Tools::sound::TAP1);

                                          auto scene = Page5::createScene();
                                          auto transition = TransitionPageTurn::create(1.2, scene,false);
                                          Director::getInstance()->replaceScene(transition);
                                      });
    next->setScale(0.8);
    next->setPosition(Vec2(winSize.width / 2 * 1.8, winSize.height / 1.1));
    
    
    auto back = MenuItemImage::create("CupcakeBack.png","CupcakeBackPress.png",
                                      [&](Ref* ref){
                                          tools->playSound(Tools::sound::TAP1);

                                          auto scene = Page3::createScene();
                                          auto transition = TransitionPageTurn::create(1.2, scene,true);
                                          Director::getInstance()->replaceScene(transition);
                                      });
    back->setScale(0.8);
    back->setPosition(Vec2(winSize.width / 2 * 0.2, winSize.height / 1.1));
    
    
    auto Button = Menu::create(next,back, NULL);
    Button->setPosition(0, 0);
    this->addChild(Button);
    
    
    
    return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
	mbirdstr.push_back("birdblue");
	mbirdstr.push_back("birdred");
	mbirdstr.push_back("birdyellow");
	mbirdclolor=rand()%100%3;
//	EFFECT_PLAY(true,MUSIC_SWOOSHING);
	//播放背景音乐
	// CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_JUMP, true);
	////////////////////////////////////////////////////
	// 下面添加创建自己的Sprite的代码
	////////////////////////////////////////////////////

	mScreenSize = CCDirector::sharedDirector()->getWinSize();
	mFPS=CCDirector::sharedDirector()->getAnimationInterval();


	mfac=CCDirector::sharedDirector()->getContentScaleFactor();
	mfax = 320.f/mScreenSize.width;
	//gBardis = 5.f*gUpVelocity/mfac;
	gBardis = mScreenSize.height*2.f/9.0f-5;
	//m_addbartime=mScreenSize.width*mFPS*mfax*1.f/2.f/MOVESPEED-10;
	//m_addbartime=3;
	initWorld();	
	for (int i = 0; i<GBACKGROUNDNUM; i++)
	{
		addBackGround(i);
	}
	int imaxgroundnum=1;
	for (int i = 0; i<imaxgroundnum; i++)
	{
		imaxgroundnum=addGround(i);
	}
	m_ilastground=imaxgroundnum-1;
	CCLOG("m_pLastGround->boundingBox() first x:%f,:%f  ", (m_pGroundVec[m_ilastground])->boundingBox().getMaxX(),
		(m_pGroundVec[m_ilastground])->boundingBox().size.width);
	addStart();
	addTop();
	//addRate();
	//addFlappyBird();

	addBird();
	addScore();
	addGameOver();

	m_pScore->setVisible(false);
	m_pGameOver->setVisible(false);
	this->goReady();
	addBarContainer();

	setTouchEnabled(true);
	myflag=0;
	m_istatus=GETREADY;
	m_bhitbar=false;
	//scheduleOnce(schedule_selector(HelloWorld::startGame), 1);
	this->scheduleUpdate();
	//创建动画
	initAction();
	myangle=0.f;
	return true;
}