Ejemplo n.º 1
0
bool AboutLayer::init()
{
	//调用父类的初始化
    if ( !Layer::init() )
    {
        return false;
    }

	//最大的背景
	Sprite *background = Sprite::create(PIC_PATH+std::string("background.png"));
	background->setPosition(Point(480,270));
	this->addChild(background,0);
	//菜单背景
	Sprite *aboutGame = Sprite::create(PIC_PATH+std::string("aboutGame.png"));
	aboutGame->setPosition(Point(480,270));
	this->addChild(aboutGame,1);

	MenuItemImage* backItem = MenuItemImage::create(
		PIC_PATH+std::string("choose_game_exit_btn.png"),
		PIC_PATH+std::string("choose_game_exit_btn.png"),
		 CC_CALLBACK_1(AboutLayer::menuReturnCallback, this) //点击时执行的回调方法

	);
	backItem->setPosition(Point(60,485));
	auto backMenu = Menu::create(backItem,NULL);
	//设置菜单位置
	backMenu->setPosition(Point::ZERO);
	this->addChild(backMenu,3);

	return true;
}
Ejemplo n.º 2
0
bool Skill::init(SkillType skillType)
{
	string img = IMG_PLAYER;
	ccMenuCallback callback;
	switch (skillType)
	{
	case SkillType::SKILL_THUNDER:
		{
			img += "skill2.png";
			callback = CC_CALLBACK_0(Skill::thunder, this);
			break;
		}
	case SkillType::SKILL_REINFORCE:
		{
			img += "skill1.png";
			callback = CC_CALLBACK_0(Skill::thunder, this);
			break;
		}
	default:
		return false;
	}
    MenuItemImage* skill = MenuItemImage::create(img, img, callback);
	_skillSize = skill->getContentSize();
    Menu *menu = Menu::create(skill, NULL);
    menu->setAnchorPoint(Vec2(0, 0));
    menu->setPosition(Vec2(0, 0));
    this->addChild(menu);
	return true;
}
// Menus
void GameLevelLayer::gameOver(bool playerDidWin)
{
	m_isGameOver = true;
    std::string gameText;
    
	if (playerDidWin)
    {
		gameText = "You Won!";
	}
    else
    {
		gameText = "You have Died!";
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("hurt.wav");
	}
    
    Menu* pMenu = CCMenu::create();
    pMenu->setPosition(Vec2(240, -100));
    
    MenuItemFont *diedLabel = MenuItemFont::create(gameText);
    diedLabel->setFontName("Marker Felt");
    diedLabel->setFontSize(24);
    diedLabel->setPosition(Vec2(240, 200));
    pMenu->addChild(diedLabel);
    
    MoveBy *slideIn = MoveBy::create(1.0, Vec2(0,250));
    
    MenuItemImage *replay = MenuItemImage::create("replay.png", "replay.png", "replay.png");
    replay->setPosition(Point::ZERO);
    replay->setCallback(CC_CALLBACK_1(GameLevelLayer::replayButtonCallback, this));
    pMenu->addChild(replay);
    
    this->addChild(pMenu, 1);
    
    pMenu->runAction(slideIn);
}
void ScoreAPIScene::buildScene()
{
    // Call super build scene.
    BaseScene::buildScene();
    BaseScene::addTipBoard("Do you know that store user score on Facebook? Compare friends score and build a leaderboard in just 1 function call");

    
    SpriteBatchNode* batchNode = SpriteBatchNode::create(PNG_FILE(kRESOURCE_SCORE));
    this->addChild(batchNode);
    
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_SCORE));
    buildHeader(-1, "Score APIs", "Generate interesting stories by updating scores");
    
    MenuItemImage* menuItem = NULL;
    
    menuItem = this->buildAndPlaceTile("btn_reset_score_nrl",      "btn_reset_score_prd",      1, 0);
    menuItem->setCallback(CC_CALLBACK_1(ScoreAPIScene::resetUserScore, this));
    
    menuItem = this->buildAndPlaceTile("btn_submit_score_nrl",     "btn_submit_score_prd",     1, 1);
    menuItem->setCallback(CC_CALLBACK_1(ScoreAPIScene::submitUserScore, this));
    
    //menuItem = this->buildAndPlaceTile("btn_reset_tournament_nrl", "btn_reset_tournament_prd", 1, 1);
    //menuItem->setTarget(this, menu_selector(ScoreAPIScene::resetTournamentScore));
    
    menuItem = this->buildAndPlaceTile("btn_achievement_nrl",      "btn_achievement_prd",      0, 2);
    menuItem->setCallback(CC_CALLBACK_1(ScoreAPIScene::publishAnAchievement, this));
}
Ejemplo n.º 5
0
void PianoKeyBoard::drawImageKey(cocos2d::Node *node, PianoKey *key, int zOder)
{
    if (key == NULL) {
        
        return ;
    }
    
    Rect rct = key->rect_;
    
    MenuItemImage *keySprite  ;

    if (key->type_ != BLACK_KEY) {
        keySprite = MenuItemImage::create(whiteNormalPix_, whiteDownPix_, CC_CALLBACK_1(PianoKeyBoard::keyTouched, this)) ;
        keySprite->setPosition(rct.origin.x, rct.origin.y) ;
    }else
    {
        keySprite = MenuItemImage::create(blackNormalPix_, blackDownPix_, CC_CALLBACK_1(PianoKeyBoard::keyTouched, this)) ;
        keySprite->setPosition(rct.origin.x, rct.origin.y+119) ;
    }
    
    keySprite->setAnchorPoint(Point::ZERO) ;
    keySprite->setTag(key->note_) ;

    node->addChild(keySprite, zOder) ;
    

}
Ejemplo n.º 6
0
void PlayMenu::setupGUI()
{

    LabelTTF*  timerLabel=  LabelTTF::create(NEXT_LIFE_IN, GAME_LABEL_FONT_NATHAN, 29);
    timerLabel->setPosition(ccp(winSize.width/2-170,winSize.height/2+430));
	timerLabel->setColor(Color3B::BLUE);
    timerLabel->setTag(KTAG_PLYMENU_COINSLBL);

    timerForLife=  LabelTTF::create("", GAME_LABEL_FONT_NATHAN, 29);
    timerForLife->setPosition(ccp(winSize.width/2-20,winSize.height/2+430));
	timerForLife->setColor(Color3B::BLACK);
    timerForLife->setTag(KTAG_PLYMENU_COINSLBL);
    
    Sprite* bckg = Sprite::create(BACKGROUND);
    bckg->setPosition( ccp(winSize.width/2,winSize.height/2) );
    CCLOG("win size %f ",winSize.width);
    this->addChild(bckg, 0-KTAG_LAYERING_PARAM);
    
    MenuItemImage *playMenuItem = MenuItemImage::create(PLAY_IMAGE, PLAY_IMAGE_PRESSED, this,menu_selector(PlayMenu::play));
    
    Menu *menu = Menu::create(playMenuItem,NULL);
    
    menu->setPosition(ccp(0, 0));
    playMenuItem->setPosition(ccp(winSize.width/2, winSize.height/2-(275)));
      
    this->addChild(menu);
    
}
Ejemplo n.º 7
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.º 8
0
UI::UI( cocos2d::Layer *layer, int &gameState )
{
    this->gameState = &gameState;
    
    Size screenSize = Director::getInstance( )->getVisibleSize( );
    Vec2 origin = Director::getInstance( )->getVisibleOrigin( );

    MenuItemSprite *pauseItem = MenuItemSprite::create( Sprite::create( PAUSE_BUTTON ), Sprite::create( PAUSE_BUTTON_PRESSED ), Sprite::create( PAUSE_BUTTON_PRESSED ), CC_CALLBACK_1( UI::PauseGame, this ) );
    pauseItem->setPosition( Vec2( screenSize.width - ( pauseItem->getContentSize( ).width / 2 ) + origin.x, screenSize.height - ( pauseItem->getContentSize( ).height / 2 ) + origin.y ) );
    
    Menu *menuButtons = Menu::create( pauseItem, NULL );
    menuButtons->setPosition( Vec2::ZERO );
    layer->addChild( menuButtons );
    
    pausebackground = Sprite::create( PAUSE_BACKGROUND );
    pausebackground->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
    pausebackground->setOpacity( 0 );
    layer->addChild( pausebackground );
    
    
    MenuItemImage *overlayPauseWindowItem = MenuItemImage::create( PAUSE_WINDOW, PAUSE_WINDOW, PAUSE_WINDOW, NULL );
    MenuItemSprite *resumeItem = MenuItemSprite::create( Sprite::create( RESUME_BUTTON ), Sprite::create( RESUME_BUTTON_PRESSED ), Sprite::create( RESUME_BUTTON ), CC_CALLBACK_1( UI::PauseGame, this ) );
    resumeItem->setPosition( Vec2( -overlayPauseWindowItem->getContentSize( ).width / 4, resumeItem->getPositionY( ) ) );
    MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
    mainMenuItem->setPosition( Vec2( overlayPauseWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
    
    pauseMenu = Menu::create( overlayPauseWindowItem, resumeItem, mainMenuItem, NULL );
    pauseMenu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
    layer->addChild( pauseMenu );
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
      
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
        CC_CALLBACK_1(HelloWorld::menuCloseCallback,this)
                      );

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

	// create menu, it's an autorelease object
	Menu* pMenu = Menu::create(pCloseItem, NULL);
	pMenu->setPosition(Point(0,0));
	this->addChild(pMenu, 1);

    return true;
}
Ejemplo n.º 10
0
void UI::ShowGameOver( cocos2d::Layer *layer )
{
    Size screenSize = Director::getInstance( )->getVisibleSize( );

    Sprite *background = Sprite::create( GAME_OVER_BACKGROUND );
    background->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
    background->setOpacity( 0 );
    layer->addChild( background );
    background->runAction( Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), FadeIn::create( GAME_OVER_BACKGROUND_FADE_IN_TIME ), NULL ) );
    
    MenuItemImage *overlayWindowItem = MenuItemImage::create( GAME_OVER_WINDOW, GAME_OVER_WINDOW, GAME_OVER_WINDOW, NULL );
    MenuItemSprite *retryItem = MenuItemSprite::create( Sprite::create( RETRY_BUTTON ), Sprite::create( RETRY_BUTTON_PRESSED ), Sprite::create( RETRY_BUTTON ), CC_CALLBACK_1( UI::Retry, this ) );
    retryItem->setPosition( Vec2( overlayWindowItem->getContentSize( ).width / 4, retryItem->getPositionY( ) ) );
    MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
    mainMenuItem->setPosition( Vec2( -overlayWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
    
    
    Menu *menu = Menu::create( overlayWindowItem, retryItem, mainMenuItem, NULL );
    menu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
    layer->addChild( menu );
    

    EaseBounceOut *menuActionEasing = EaseBounceOut::create( MoveTo::create( MENU_MOVE_BOUNCE_DURATION, SonarCocosHelper::UI::GetScreenCenter( ) ) );
    Sequence *menuShowSeq = Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), menuActionEasing, NULL );
    menu->runAction( menuShowSeq );
}
Ejemplo n.º 11
0
void GamePlay::gameHelp() {
	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/button.mp3");
	boardMenuPause->setVisible(false);

	boardMenuHelp = Sprite::create("board.png");
	boardMenuHelp->setPosition(
			Vec2(visibleSize.width / 2, visibleSize.height / 2));
	boardMenuHelp->setZOrder(30);
	this->addChild(boardMenuHelp);

	float haflHeight = boardMenuHelp->getContentSize().height / 2;
	float haflWidth = boardMenuHelp->getContentSize().width / 2;

	Sprite* text = Sprite::create("howtoplaytext.png");
	text->setPosition(Vec2(haflWidth + PADDING / 2, haflHeight));
	text->setZOrder(40);
	boardMenuHelp->addChild(text);

	MenuItemImage* closeBtn = MenuItemImage::create("menu_closeBtn.png",
			"menu_closeBtn.png", CC_CALLBACK_0(GamePlay::gameCloseMenu, this));
	auto menuClose = Menu::create(closeBtn, nullptr);
	menuClose->setZOrder(40);
	menuClose->setPosition(
			Vec2(haflWidth * 2 - closeBtn->getContentSize().width - PADDING,
					haflHeight * 2 - closeBtn->getContentSize().height
							- PADDING));
	boardMenuHelp->addChild(menuClose);
}
Ejemplo n.º 12
0
bool GameOver::init()
{
    bool ret = false;
    do {
        CC_BREAK_IF(!Layer::init());
        Sprite *backGround1 = Sprite::createWithSpriteFrameName("gameover.png");
        backGround1->setAnchorPoint(Point(0, 0));
        backGround1->setPosition(Point(0, 0));
        this->addChild(backGround1, -1, 0);

        Size size = Director::getInstance()->getWinSize();

        MenuItemImage *item = MenuItemImage::create("ui/shoot_background/btn_finish.png"
            , "ui/shoot_background/btn_finish.png", menuCallback);
        Menu *menu = Menu::create(item, NULL);
        addChild(menu);
        item->setAnchorPoint(Point(0, 0));
        menu->setPosition(Point(0, 0));
        item->setPosition(Point(size.width - item->getContentSize().width, 0));

        m_scoreLabel = LabelTTF::create("0", "Arial", 28);
        m_scoreLabel->setFontSize(40);
        addChild(m_scoreLabel);

        m_scoreLabel->setPosition(Point(size.width * 0.5, size.height * 0.5));
        ret = true;
    } while (0);
    return ret;
}
void OpenGraphAPIScene::buildScene()
{
    // Call super build scene.
    BaseScene::buildScene();
    BaseScene::addTipBoard("Do you know that Open Graph is the coolest feature from Facebook? You can share live game action on the Facebook with just one function call at right time.");

    
    SpriteBatchNode* batchNode = SpriteBatchNode::create(PNG_FILE(kRESOURCE_OG));
    this->addChild(batchNode);
    
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_OG));
    
    buildHeader(-1, "Open Graph Stories", "Increase your user base by publishing open graph stories");
    
    // Build the tiles.
    MenuItemImage* menuItem = NULL;
    
    menuItem = this->buildAndPlaceTile("btn_og_earn_achievement_nrl",   "btn_og_earn_achievement_prd",  1, 0);
    menuItem->setCallback(CC_CALLBACK_1(OpenGraphAPIScene::earnAchievement, this));
    
    menuItem = this->buildAndPlaceTile("btn_og_defeat_friend_nrl",      "btn_og_defeat_friend_prd",     1, 1);
    menuItem->setCallback(CC_CALLBACK_1(OpenGraphAPIScene::defeatAFriend, this));
    
    menuItem = this->buildAndPlaceTile("btn_og_find_item_nrl",          "btn_og_find_item_prd",         0, 2);
    menuItem->setCallback(CC_CALLBACK_1(OpenGraphAPIScene::findAGuitarItem, this));
    
    menuItem = this->buildAndPlaceTile("btn_og_complete_lvl_nrl",       "btn_og_complete_lvl_prd",      2, 2);
    menuItem->setCallback(CC_CALLBACK_1(OpenGraphAPIScene::completeALevel, this));
    
}
Ejemplo n.º 14
0
TestController::TestController()
: _beginPos(PointZero)
{
    // add close menu
    MenuItemImage *pCloseItem = MenuItemImage::create(s_pPathClose, s_pPathClose, CC_CALLBACK_1(TestController::closeCallback, this) );
    Menu* pMenu =Menu::create(pCloseItem, NULL);

    pMenu->setPosition( PointZero );
    pCloseItem->setPosition(ccp( VisibleRect::right().x - 30, VisibleRect::top().y - 30));

    // add menu items for tests
    _itemMenu = Menu::create();
    for (int i = 0; i < g_testCount; ++i)
    {
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
//         LabelBMFont* label = LabelBMFont::create(g_aTestNames[i].c_str(),  "fonts/arial16.fnt");
// #else
        LabelTTF* label = LabelTTF::create( g_aTestNames[i].test_name, "Arial", 24);
// #endif        
        MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(TestController::menuCallback, this));

        _itemMenu->addChild(pMenuItem, i + 10000);
        pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));
    }

    _itemMenu->setContentSize(CCSizeMake(VisibleRect::getVisibleRect().size.width, (g_testCount + 1) * (LINE_SPACE)));
    _itemMenu->setPosition(s_tCurPos);
    addChild(_itemMenu);

    setTouchEnabled(true);

    addChild(pMenu, 1);

}
Ejemplo n.º 15
0
bool SceneOver::init()
{

    if ( !Layer::init() )
    {
        return false;
    }
	//重新开始游戏按钮
	MenuItemImage *pRestartItem = MenuItemImage::create(
		"pause_restart.png",
		"pause_restart.png",
		CC_CALLBACK_1(SceneOver::menuRestart, this)
	);

	pRestartItem->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 20));

	//回主界面
	MenuItemImage *pLoginItem = MenuItemImage::create(
		"pause_login.png",
		"pause_login.png",
		CC_CALLBACK_1(SceneOver::menuLogin, this)
	);

	pLoginItem->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 70));

	// create menu, it's an autorelease object
	Menu* pMenu = Menu::create(pRestartItem,pLoginItem,NULL);
	pMenu->setPosition(Vec2(0.0f, 0.0f));
	this->addChild(pMenu, 2);


    return true;
}
Ejemplo n.º 16
0
void gdShow::ButonCallback(Ref* resender)
{
	//如果当前是最后一张图片,点按钮就直接开始游戏
	if (this->getChildByTag(4)->getPositionX() == Director::getInstance()->getVisibleSize().width / 2)
	{
		auto sc = GameScene::createSceneWithId(2);
		auto reScene = TransitionJumpZoom::create(0.0f, sc);
		Director::getInstance()->replaceScene(sc);
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sound/Blip.wav");
		auto m = (MenuItemSprite*)resender;
		m->setEnabled(false);
		return;
	}


	CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sound/Blip.wav");
	MenuItemImage* m = (MenuItemImage*)resender;
	m->setEnabled(false);
	CallFunc* call = CallFunc::create([&](){nextMenuItem->setEnabled(true); });
	MoveBy* moveby1 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby2 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby3 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby4 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	this->getChildByTag(2)->runAction(EaseSineInOut::create(moveby2));
	this->getChildByTag(3)->runAction(EaseSineInOut::create(moveby3));
	this->getChildByTag(4)->runAction(EaseSineInOut::create(moveby4));
	this->getChildByTag(1)->runAction(EaseSineInOut::create(Sequence::create(moveby1, call, NULL)));
}
Ejemplo n.º 17
0
void GamePlayScene::playCallback(cocos2d::Object *pSender)
{
    MenuItemImage *item = (MenuItemImage *)pSender ;
    
    
    item->setNormalSpriteFrame(SpriteFrame::create("btn-pause-n.png", playBtnRct)) ;
     item->setSelectedSpriteFrame(SpriteFrame::create("btn-pause-p.png", playBtnRct)) ;
}
Ejemplo n.º 18
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();
    Point origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(PointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

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

    // add "HelloWorld" splash screen"
    Sprite* pSprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    return true;
}
Ejemplo n.º 19
0
bool GameLayer::init()
{
    if (Layer::init()) {
        
        array = __Array::create();
        array->retain();
        
        __Dictionary* tempDict = __Dictionary::createWithContentsOfFile("myplist.plist");
        tempDict->objectForKey("maxVelocity");


        
        // TODO: read plist
        
        Vec2 origin = Director::getInstance()->getVisibleOrigin();
        Size screenSize = Director::getInstance()->getVisibleSize();
        
        // Label.
        Label* label = Label::createWithTTF("Hello world!", "fonts/Marker Felt.ttf", 13);
        label->setPosition(Vec2(origin.x + screenSize.width/2, origin.y + screenSize.height / 2));
//        label->setAnchorPoint(Vec2(1,1));
        label->setColor(Color3B::WHITE);
        this->addChild(label, 1);
        
        // Menu items.
        MenuItemImage* button = MenuItemImage::create("test.jpg", "bc003_02.png", CC_CALLBACK_0(GameLayer::changeScene,this));
        button->setPosition(Vec2(0,0));
        
        // Menu.
        Menu* menu = Menu::create(button, NULL);
        menu->setPosition(Vec2(origin.x + screenSize.width/2, origin.y + screenSize.height / 2));
        this->addChild(menu);
        
        tempDict->setObject(label, "hello_world_label");
        
        array->addObject(label);
        
        
        
        
        
        
        
        
        
        
        
        
        
        Label *templabel = (Label*)tempDict->objectForKey("hello_world_label");
        
        return true;
    }
    
    return false;
}
Ejemplo n.º 20
0
// on "init" you need to initialize your instance
bool OptionsMenu::init()
{
    Size visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    Vec2 origin = CCDirector::sharedDirector()->getVisibleOrigin();

    scrollingBgLayer = new ScrollingBgLayer(3.0);
    this->addChild(scrollingBgLayer);


    LabelBMFont *nameLabel = LabelBMFont::create("Options Menu","PixelFont.fnt");
    nameLabel->setPosition(visibleSize.width/2, visibleSize.height * 0.8);
    this->addChild(nameLabel);

    MenuItemImage *presetItem = MenuItemImage::create("_bookgame_UI__resume.png",
                                "_bookgame_UI__resume.png",
                                CC_CALLBACK_1(OptionsMenu::reset, this));
    presetItem->setPosition(ccp(visibleSize.width/2 - visibleSize.width * 0.125,  visibleSize.height * 0.5));


    MenuItemImage *pmainMenuItem = MenuItemImage::create("_bookgame_UI_mainmenu.png",
                                   "_bookgame_UI_mainmenu.png",
                                   CC_CALLBACK_1(OptionsMenu::mainMenu, this));
    pmainMenuItem->setPosition(Vec2(visibleSize.width/2 + visibleSize.width * 0.125, visibleSize.height * 0.5 ));



    //sound onoff items
    soundOnItem = MenuItemImage::create("_bookgame_UI_soundON.png","_bookgame_UI_soundON.png", this,NULL);
    soundOffItem = MenuItemImage::create("_bookgame_UI_soundOFF.png","_bookgame_UI_soundOFF.png", this,NULL);

    bool isPaused = CCUserDefault::sharedUserDefault()->getBoolForKey("tinyBazooka_kSoundPausedKey");

    MenuItemToggle* soundToggleItem;
    if(isPaused == false) {
        soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
                          soundOnItem, soundOffItem,NULL);
    } else {
        soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
                          soundOffItem, soundOnItem,NULL);
    }

    soundToggleItem->setPosition(ccp(visibleSize.width* 0.5, visibleSize.height * 0.5 ));




    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pmainMenuItem, presetItem,soundToggleItem, NULL);
    pMenu->setPosition(Vec2::ZERO);
    this->addChild(pMenu, 10);

    this->scheduleUpdate();

    return true;

}
Ejemplo n.º 21
0
void UserLoginScene::buttonCallback(Ref* sender)
{
    MenuItemImage *pSender = (MenuItemImage*)sender;
    
    UserDefault::getInstance()->setIntegerForKey("Player_ID", pSender->getTag());

    log("User key for login:%d",UserLoginKey);
    Scene *startScene  =  CGameScene::createScene();
    Director::getInstance()->replaceScene(startScene);
}
Ejemplo n.º 22
0
void TBaseObject::onEnter()
{
    LayerColor::onEnter();
    
    MenuItemImage* item = MenuItemImage::create("GameRes//interface//playnormal.png","GameRes//interface//playselected.png",CC_CALLBACK_1(TBaseObject::ProxyLeftDown, this));
    Menu* menu = Menu::create(item,NULL,NULL,NULL);
    menu->setPosition(Point::ZERO);
    item->setPosition(Point(TVisibleRect::center().x, TVisibleRect::center().y + item->getContentSize().height / 2));
    this->addChild(menu,9999);
}
Ejemplo n.º 23
0
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage)
{
    MenuItemImage *ret = new (std::nothrow) MenuItemImage();
    if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, (const ccMenuCallback&)nullptr))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return nullptr;
}
Ejemplo n.º 24
0
// XXX deprecated
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector)
{
    MenuItemImage *ret = new (std::nothrow) MenuItemImage();
    if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return nullptr;
}
Ejemplo n.º 25
0
MenuItemImage* MenuItemImage::create()
{
    MenuItemImage *ret = new (std::nothrow) MenuItemImage();
    if (ret && ret->init())
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return nullptr;
}
Ejemplo n.º 26
0
MenuItemImage* MenuItemImage::create()
{
    MenuItemImage *pRet = new MenuItemImage();
    if (pRet && pRet->init())
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
Ejemplo n.º 27
0
// XXX deprecated
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector)
{
    MenuItemImage *pRet = new MenuItemImage();
    if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
Ejemplo n.º 28
0
MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage)
{
    MenuItemImage *pRet = new MenuItemImage();
    if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, (const ccMenuCallback&)nullptr))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
Ejemplo n.º 29
0
// on "init" you need to initialize your instance
bool TestIAP::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    MyPurchase::getInstance()->loadIAPPlugin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    auto pEGLView = Director::getInstance()->getOpenGLView();
    Point posBR = Point(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y);
    Point posTL = Point(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height);

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestIAP::menuBackCallback, this));
    Size backSize = pBackItem->getContentSize();
    pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pBackItem, NULL);
    pMenu->setPosition( Point::ZERO );
    this->addChild(pMenu, 1);

    Point posStep = Point(220, -150);
    Point beginPos = posTL + (posStep * 0.5f);
    int line = 0;
    int row = 0;
    for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
    	MenuItemImage* pMenuItem = MenuItemImage::create(s_EventMenuItem[i].id.c_str(), s_EventMenuItem[i].id.c_str(),
    			CC_CALLBACK_1(TestIAP::eventMenuCallback, this));
        pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);

        Point pos = beginPos + Point(posStep.x * row, posStep.y * line);
        Size itemSize = pMenuItem->getContentSize();
        if ((pos.x + itemSize.width / 2) > posBR.x)
		{
			line += 1;
			row = 0;
			pos = beginPos + Point(posStep.x * row, posStep.y * line);
		}
        row += 1;
        pMenuItem->setPosition(pos);
    }

    return true;
}
Ejemplo n.º 30
0
void PadControlLayer::initSprite()
{
    velocity = Vec2::ZERO;
    isPressed = false;
    isButtonA = false;
    isButtonB = false;
    isStart = false;
    isSelect = false;
    
    float factor = 1.5;
    float JoySize = _visibleSize.height*124.8*factor/720;      // 124.8
    
    float edgeLong =  _visibleSize.height* 100*factor/720;   // 100
    kCenter = Vec2( edgeLong, edgeLong );
    _JOYSTICK_RADIUS = edgeLong;
    _THUMB_RADIUS = _visibleSize.height*20.0*factor/720;
    
    joystickBackground = Sprite::create("gamepad/ThumbPadRing.png");
    joystickBackground->setScale( JoySize/78 );
    joystickBackground->setPosition(kCenter);
    this->addChild(joystickBackground,0);
    
    float thumbSize = _visibleSize.height*57.6*factor/720;
    thumbPad = Sprite::create("gamepad/ThumbPad.png");
    thumbPad->setScale(thumbSize/64);
    thumbPad->setPosition(kCenter);
    this->addChild(thumbPad,1);
    
    float thumbab = _visibleSize.height*64*factor/720;
    buttonA = Sprite::create("gamepad/ButtonA.png");
    buttonA->setScale(thumbab/64);
    buttonA->setPosition(Vec2(_visibleSize.width - _visibleSize.height*160*factor/720, _visibleSize.height*80*factor/720));
    this->addChild(buttonA,1);
    
    buttonB = Sprite::create("gamepad/ButtonB.png");
    buttonB->setScale(thumbab/64);
    buttonB->setPosition(Vec2(_visibleSize.width - _visibleSize.height*70*factor/720, _visibleSize.height*115*factor/720));
    this->addChild(buttonB,1);
    
    float startSize = _visibleSize.width*130/1280;
    MenuItemImage *start = MenuItemImage::create("gamepad/start.png", "gamepad/start.png", CC_CALLBACK_1(PadControlLayer::nesStart, this));
    start->setScale(startSize/600);
    start->setPosition(_visibleSize.width - _visibleSize.width*100/1280, _visibleSize.height /2);
    
    MenuItemImage *select = MenuItemImage::create("gamepad/select.png", "gamepad/select.png", CC_CALLBACK_1(PadControlLayer::nesSelect, this));
    select->setScale(startSize/600);
    select->setPosition(_visibleSize.width - _visibleSize.width*100/1280, _visibleSize.height /2 - _visibleSize.height *70/720);
    
    float nesCardSize = _visibleSize.height*65/720;
    MenuItemImage *nescard = MenuItemImage::create("gamepad/nescard.png", "gamepad/nescard.png", CC_CALLBACK_1(PadControlLayer::nesSelectGame, this));
    nescard->setScale(nesCardSize/200);
    nescard->setPosition(Vec2(_visibleSize.width*50/1280, _visibleSize.height - _visibleSize.height*50/720));
    
    Menu *menu1 = Menu::create(start, select, nescard ,NULL);
    menu1->setPosition(Vec2::ZERO);
    this->addChild(menu1,1);
}