Exemplo n.º 1
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) ;
    

}
Exemplo n.º 2
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;
}
// on "init" you need to initialize your instance
bool ItemLayer::init() {
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() ) {
        return false;
    }

    this->setKeypadEnabled(true);

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

    auto title = LabelTTF::create("Item", "Arial", 24);
    title->setPosition( Point(size.width / 2, size.height - 50));
    this->addChild(title, 1);

    /////////////////////////////
    // 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(
                                        "b1.png",
                                        "b2.png",
                                        CC_CALLBACK_1(ItemLayer::menuBackCallback,this) );
    pCloseItem->setPosition( Point(pCloseItem->getContentSize().width / 2 , 50) );

    // create menu, it's an autorelease object
    auto pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition( Point::ZERO );
    this->addChild(pMenu, 1);
    
    // add next menu
    MenuItemImage *pNextItem = MenuItemImage::create(
                                                          "f1.png",
                                                          "f2.png",
                                                          CC_CALLBACK_1(ItemLayer::menuNextCallback,this) );
    pNextItem->setPosition( Point(size.width - pNextItem->getContentSize().width / 2, 50) );
    
    // create menu, it's an autorelease object
    Menu* pNextMenu = Menu::create(pNextItem, NULL);
    pNextMenu->setPosition(Point::ZERO);
    this->addChild(pNextMenu, 1);

    float step = 35;
    float yPos = 0;
    for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
        char buf[64];
		sprintf(buf, s_EventMenuItem[i].id.c_str(), itemid, counts[i]);
        
        auto label = LabelTTF::create(buf, "Arial", 30);
        MenuItemLabel* pMenuItem = MenuItemLabel::create(label,  CC_CALLBACK_1(ItemLayer::eventMenuCallback,this));
        pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
        yPos = size.height - step*i - 100;
        pMenuItem->setPosition( Point(size.width / 2, yPos));
    }

    return true;
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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;

}
Exemplo n.º 6
0
// on "init" you need to initialize your instance
bool MusicLayer_2::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    log("MusicLayer_2 init");
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    Sprite *bg = Sprite::create("background.png");
    
    // position the label on the center of the screen
    bg->setPosition(Vec2(origin.x + visibleSize.width/2,
                         origin.y + visibleSize.height /2));
    this->addChild(bg);
    
    //开始精灵
    Sprite *startSpriteNormal = Sprite::create("start-up.png");
    Sprite *startSpriteSelected = Sprite::create("start-down.png");
    
    MenuItemSprite *startMenuItem = MenuItemSprite::create(startSpriteNormal,
                                                           startSpriteSelected,
                                                           CC_CALLBACK_1(MusicLayer_2::menuItemStartCallback, this));
    startMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(700, 170)));
    
    // 设置图片菜单
    MenuItemImage *settingMenuItem = MenuItemImage::create(
                                                           "setting-up.png",
                                                           "setting-down.png",
                                                           CC_CALLBACK_1(MusicLayer_2::menuItemSettingCallback, this));
    settingMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(480, 400)));
    
    // 帮助图片菜单
    MenuItemImage *helpMenuItem = MenuItemImage::create(
                                                        "help-up.png",
                                                        "help-down.png",
                                                        CC_CALLBACK_1(MusicLayer_2::menuItemHelpCallback, this));
    helpMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(860, 480)));
    
    Menu* mu = Menu::create(startMenuItem, settingMenuItem, helpMenuItem, NULL);
    mu->setPosition(Vec2::ZERO);
    this->addChild(mu);
    
    return true;
}
Exemplo n.º 7
0
bool PauseLayer::init(GameScene* gameScene)
{
	if (!Layer::init())
		return false;

	PauseLayer::gameScene = gameScene;
	
	//background
	backGround = Sprite::create("Pause/bk.png");
	backGround->setAnchorPoint(Vec2(0, 0));
	backGround->setPosition(0, 0);
	backGround->setOpacity(0);
	this->addChild(backGround);
	//pause background
	pauseBk = Sprite::create("Pause/pause_bk.png");
	pauseBk->setPosition(640/2, 960+278/2);
	this->addChild(pauseBk);
	//menu
	Menu* menu = Menu::create();
	menu->setAnchorPoint(Vec2(0, 0));
	menu->setPosition(0, 0);
	pauseBk->addChild(menu);
	//home button 
	MenuItemImage* homeButton = MenuItemImage::create(
		"Pause/home1.png", "Pause/home2.png", "", 
		CC_CALLBACK_1(PauseLayer::buttonEvent, this));
	homeButton->setPosition(515 / 2 - 81 * 2 + 30, 85);	//position
	homeButton->setTag(BUTTON_HOME);
	menu->addChild(homeButton);
	//play button
	MenuItemImage* playButton = MenuItemImage::create(
		"Pause/play1.png", "Pause/play2.png", "",
		CC_CALLBACK_1(PauseLayer::buttonEvent, this));
	playButton->setPosition(515 / 2, 85);	//position
	playButton->setTag(BUTTON_PLAY);
	menu->addChild(playButton);
	//replay button
	MenuItemImage* replayButton = MenuItemImage::create(
		"Pause/replay1.png", "Pause/replay2.png", "",
		CC_CALLBACK_1(PauseLayer::buttonEvent, this));
	replayButton->setPosition(515 / 2 + 81 * 2 - 30, 85);	//position
	replayButton->setTag(BUTTON_REPLAY);
	menu->addChild(replayButton);

	this->setVisible(false);

	return true;
}
Exemplo n.º 8
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);

}
// 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);
}
Exemplo n.º 10
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;
}
// 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;
}
Exemplo n.º 12
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);
    
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
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);
}
Exemplo n.º 17
0
void HelloWorld::particalsystem(Object* pSender)
{
	auto size = Director::getInstance()->getWinSize();
	Scene *thirdScene = Scene::create();
	Layer *thirdLayer = Layer::create();
	ParticalSys *ps = ParticalSys::create();
	Sprite *pyc = ps->particalFire(2,Point(size.width/2,size.height/8),Point(0.2,0.7),30);
	thirdLayer->addChild(ps,1);

	MenuItemImage *hit = MenuItemImage::create("left-round.png","right-round.png", CC_CALLBACK_1(ParticalSys::particalHit,ps,2,pyc));
	hit->setPosition(Point(size.width/2,size.height/2));
	MenuItemImage *restart = MenuItemImage::create("left-round.png","right-round.png", CC_CALLBACK_1(ParticalSys::particalHit,ps,3,pyc));
	restart->setPosition(Point(size.width/2,size.height/3));
	Menu *pStartMenu = Menu::create(hit,restart,nullptr);
	pStartMenu->setPosition(Point::ZERO);
	thirdLayer->addChild(pStartMenu,1);

	thirdScene->addChild(thirdLayer,1);
	Director::getInstance()->replaceScene(thirdScene);
}
Exemplo n.º 18
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    setKeypadEnabled(true);
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    MenuItemImage *pCloseItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
    pCloseItem->setPosition(Vec2(origin.x + visibleSize.width - pCloseItem->getContentSize().width / 2,origin.y + visibleSize.height - pCloseItem->getContentSize().height / 2));
    Menu *pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(Vec2::ZERO);
    this->addChild(pMenu, 1);
    
    //创建游戏标题界面
    MenuItemImage *pItemPlay = MenuItemImage::create("playgameNormal.png", "playgameClose.png", CC_CALLBACK_1(HelloWorld::menuPlayGameCallback, this));
    pItemPlay->setPosition(Vec2(visibleSize.width / 2, visibleSize.height * 1.0f / 4.0f));
    pItemPlay->setScaleX(visibleSize.width / 600);
    pItemPlay->setScaleY(visibleSize.height / 400);
    
    Menu *pMenuPlay = Menu::create(pItemPlay, NULL);
    pMenuPlay->setPosition(Vec2::ZERO);
    this->addChild(pMenuPlay, 1);
    
    Sprite *pSprite = Sprite::create("ScenceStart.png");
    pSprite->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
    Size size = pSprite->getContentSize();
    
    pSprite->setScaleX(visibleSize.width / size.width);
    pSprite->setScaleY(visibleSize.height / size.height);
    this->addChild(pSprite, 0);
    
    return true;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
0
void ParkourGameOver::createDebug()
{
    /////////////////////////////////////////////////
    // DEBUG BUTTON
    /////////////////////////////////////////////////

    MenuItemImage* back = MenuItemImage::create("parkour_img/back_btn.png", "parkour_img/back_btn1.png", CC_CALLBACK_1(ParkourGameOver::rebootCallback, this));
    back->setPosition(Vec2(WINSIZE.width - 40, WINSIZE.height - 40));

    Menu* menu = Menu::create(back, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu);
}
Exemplo n.º 21
0
// リセットボタンの作成
void Game::showResetButton()
{
    Size bgSize = m_background->getContentSize();
    
    // リセットボタン作成
    MenuItemImage* resetButton = MenuItemImage::create(PNG_RESET, PNG_RESET, CC_CALLBACK_1(Game::menuResetCallback, this));
    resetButton->setPosition(Point(bgSize.width * 0.78, bgSize.height * 0.06));
    
    // メニュー作成
    Menu* menu = Menu::create(resetButton, NULL);
    menu->setPosition(Vec2::ZERO);
    m_background->addChild(menu);
}
Exemplo n.º 22
0
// Layerの初期処理
// ここにゲームの一番最初の処理を記載
bool PlayScene::init(){
    //////////////////////////////
    // 1. super init first
    if (!Layer::init()) {
        return false;
    }
    
    
    // 画像描画用に画面のサイズと座標開始位置を取得
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // レイヤーの背景色を設定
    // DeprecationWarnning:
    // ccc4()は非推奨のため、Color4B()を使用(中身はinline関数で、ccc4を実行していた)
    LayerColor *color = LayerColor::create(Color4B(0.0f,200.0f,0.0f,255.0f));
    this->addChild(color);

    
    // プレイ画像の追加(スプライト生成)
    auto sprite = Sprite::create("PlayBackground.png");
    // 画面中央への配置
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    // レイヤーへスプライト追加
    this->addChild(sprite, 0);

    
    // メニューボタン作成(ゲーム一時停止ボタン)
    MenuItemImage* menuButton = MenuItemImage::create(
                                                      "menubutton.png",
                                                      "menubutton.png",
                                                      [this](Ref *pSender){
                                                          auto menuLayer = MenuLayer::create(this);
                                                          this->addChild(menuLayer,100,70000);
                                                      });
    
    
    menuButton->setPosition(Vec2(origin.x + ( visibleSize.width / 3) * 2 + ( menuButton->getContentSize().width / 2 ) ,
                                      origin.y + visibleSize.height / 5));
    
    // メニュー作成
    Menu* menu = Menu::create(menuButton, NULL);
    menu->setPosition(0,0);
    this->addChild(menu);
    
    // ゲーム処理(ゲームそのものの実行)
    gameLogic();
    
    
    return true;
}
Exemplo n.º 23
0
//リセットボタン作成
void GameScene::showResetButton()
{
    Size bgSize = m_background->getContentSize();
    
    //リセットボタン作成
    MenuItemImage* resetButton = MenuItemImage::create(PNG_RESET, PNG_RESET, this, menu_selector(GameScene::menuResetCallback));
    resetButton->setPosition(ccp(bgSize.width * 0.78, bgSize.height * 0.1));
    
    //メニュー作成
    Menu* menu = Menu::create(resetButton, NULL);
    menu->setPosition(CCPointZero);
    m_background->addChild(menu);
                             
}
Exemplo n.º 24
0
void MenuLayer::setResults(Results r)
{
	auto wiew = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
	auto callback = std::bind(&MenuLayer::menuCloseCallback, this, this);
	MenuItemImage* goToLevels;
	MenuItemImage* nextReload;
	auto goNextMap = std::bind(&MenuLayer::nextMap, this, this);
	auto reload = std::bind(&MenuLayer::reloadMap, this, this);
	auto back = std::bind(&MenuLayer::backToMap, this, this);
	switch (r)
	{
	case WIN:

		nextReload = MenuItemImage::create("exit_pressed.png", "exit_pressed.png", goNextMap);
		break;
	case LOSE:

		nextReload = MenuItemImage::create("exit_pressed.png", "exitGame.png", reload);
		break;
	case PAUSE:
		nextReload = MenuItemImage::create("exitGame.png", "exit_pressed.png", back);
		break;
	default:
		break;
	}
		goToLevels = MenuItemImage::create("exitGame.png", "exit_pressed.png", callback);
		goToLevels->setAnchorPoint(Vec2(1, 0));
		goToLevels->setPosition(Vec2(wiew.width, 0));

		nextReload->setAnchorPoint(Vec2(1, 0));
		nextReload->setPosition(Vec2(wiew.width, nextReload->getBoundingBox().size.height));

		Menu* pMenu = Menu::create(goToLevels, nextReload,  NULL);
		pMenu->setPosition(Point::ZERO);
		addChild(pMenu, 1);
	
};
Exemplo n.º 25
0
void GameScene::gameOver(float delta)
{
    if (_totalMoles <=0 ) { //表示所有的地鼠都已钻出
        
        //所有地鼠都已缩回地洞,停止音效和背景音乐,显示菜单
        bool flag = true;
        for (auto mole : _molesVector) {
            if (mole->getNumberOfRunningActions() != 0) {
                flag = false;
                break;
            }
        }
        
        if (flag) {
            _gameOver = true;
            
            MenuItemImage *goItem = nullptr;
            if (_score < _successScore) { //游戏失败
                goItem = MenuItemImage::create("btn-continue.png", "btn-continue.png", [&](Ref *pSender){
                    Director::getInstance()->replaceScene(GameScene::createScene());
                });
            }
            else { //进入下一关
                goItem = MenuItemImage::create("btn-next.png", "btn-next.png", [&](Ref *pSender){
                    _level += 1;
                    Director::getInstance()->replaceScene(GameScene::createScene());
                });
            }
            
            CocosDenshion::SimpleAudioEngine::getInstance()->stopAllEffects();
            CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
            
            Size visibleSize = Director::getInstance()->getVisibleSize();
            goItem->setPosition(visibleSize.width/2, visibleSize.height/2+60);
            
            auto againItem = MenuItemImage::create("btn-again.png", "btn-again.png", [&](Ref *pSender){
                Director::getInstance()->replaceScene(HelloWorld::createScene());
            });
            againItem->setPosition(visibleSize.width/2, visibleSize.height/2-60);
            
            auto menu = Menu::create(goItem, againItem, NULL);
            menu->setPosition(Vec2::ZERO);
            this->addChild(menu, 6);
            
            return;
        }
        
    }
}
Exemplo n.º 26
0
bool HMenu::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    sceneLevel = 9999;
    
    //播放菜单场景的音乐
    SimpleAudioEngine::getInstance()->playBackgroundMusic("menuMusic.mp3",true);
    
    //获取整个设备的尺寸
    auto size = Director::getInstance()->getWinSize();
    
    //创建Menu背景
    Sprite* sp1 = Sprite::create("img_bg_logo.jpg");
    sp1->setPosition(Vec2(size.width*0.5,size.height*0.5));
    addChild(sp1);
    
    Sprite* sp2 = Sprite::create("LOGO.png");
    sp2->setPosition(Vec2(size.width*0.5,size.height*2/3+15));
    addChild(sp2);
    
    //创建Menu菜单项-play
	MenuItemImage * itemPlay= MenuItemImage::create("play_nor.png", "play_pre.png",CC_CALLBACK_1(HMenu::playIsPressed, this));
    
    //创建Menu菜单项-score
    MenuItemImage * itemScore= MenuItemImage::create("score_nor.png", "score_pre.png",CC_CALLBACK_1(HMenu::scoreIsPressed, this));
    itemScore->setPosition(Vec2(0,-itemScore->getContentSize().height-20));
    
    //创建Menu菜单项-about
    MenuItemImage * itemAbout= MenuItemImage::create("about_nor.png", "about_pre.png",CC_CALLBACK_1(HMenu::aboutIsPressed, this));
    itemAbout->setPosition(Vec2(0,-itemScore->getContentSize().height*2-40));
    
    //创建Menu菜单项-settings
    MenuItemImage * itemSettings = MenuItemImage::create("setting.png", "setting.png",CC_CALLBACK_1(HMenu::SetttingsIsPressed, this));
    itemSettings->setPosition(Vec2(0,-itemScore->getContentSize().height*3-40));
    
    //利用3个菜单项创建Menu菜单
    Menu * menu = Menu::create(itemPlay,itemScore,itemAbout,itemSettings,NULL);
    menu->setPosition(Vec2(size.width/2, size.height/3-10));
    addChild(menu);
    menu->alignItemsVerticallyWithPadding(10);
    
    return true;
}
Exemplo n.º 27
0
void UI::createLevelEditorFilePopup()
{
	Size visibleSize = Director::getInstance()->getVisibleSize();

	MenuItemFont* addTextureObject = MenuItemFont::create("choose file", CC_CALLBACK_0(UI::nullCallback, this));
	addTextureObject->setFontNameObj("Segoe UI");
	addTextureObject->setFontSizeObj(34);
	addTextureObject->setPosition(visibleSize.width * 0.5f, visibleSize.height - 30);

	MenuItemFont* scrollUpObject = MenuItemFont::create("up", CC_CALLBACK_0(LevelEditor::moveFileSelectUpCallback, pLevelEditor));
	scrollUpObject->setFontNameObj("Segoe UI");
	scrollUpObject->setFontSizeObj(34);
	scrollUpObject->setPosition(visibleSize.width - 50, visibleSize.height - 30);

	MenuItemFont* scrollDownObject = MenuItemFont::create("down", CC_CALLBACK_0(LevelEditor::moveFileSelectDownCallback, pLevelEditor));
	scrollDownObject->setFontNameObj("Segoe UI");
	scrollDownObject->setFontSizeObj(34);
	scrollDownObject->setPosition(visibleSize.width - 50, 30);

	MenuItemImage* scrollBackground = MenuItemImage::create("Resources/pictures/generic/ui_background.png", "ui_background.png", CC_CALLBACK_0(UI::nullCallback, this));
	scrollBackground->setPosition(visibleSize.width * 0.5f, visibleSize.height * 0.5f);
	scrollBackground->setScale(400, visibleSize.height);

	int paddingTop = 60;
	Vector<MenuItem*> lMenuItems;
	lMenuItems.pushBack(addTextureObject);
	for (string s : getAllFilesInFolder("Resources/pictures/tiles"))
	{
		MenuItemFont* menuItem = MenuItemFont::create(s, CC_CALLBACK_1(LevelEditor::chooseFileCallback, pLevelEditor, s, levelType));
		menuItem->setFontNameObj("Segoe UI");
		menuItem->setFontSizeObj(24);
		menuItem->setPosition(visibleSize.width * 0.5f, visibleSize.height - paddingTop);
		paddingTop += 30;
		lMenuItems.pushBack(menuItem);
	}
	auto menu = Menu::createWithArray(lMenuItems);
	auto scrollMenu = Menu::create(scrollBackground, scrollDownObject, scrollUpObject, NULL);
	scrollMenu->retain();
	scrollMenu->setPosition(0, 0);
	menu->retain();
	menu->setPosition(0, 0);
	m_pLevelEditor->addChild(menu);
	m_pLevelEditor->addChild(scrollMenu, -10);
	pLevelEditor->ChooseFileMenu = menu;
	pLevelEditor->ChooseFileNavMenu = scrollMenu;
}
Exemplo n.º 28
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",
                                                      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::ZERO);
    this->addChild(pMenu, 1);
    
    Point beginPos = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 50);
    float step = 60.0f;
    int nCaseCount = sizeof(g_testCases) / sizeof(std::string);
    for (int i = 0; i < nCaseCount; ++i) {
        std::string caseName = g_testCases[i];
        MenuItemFont *pItem = MenuItemFont::create(caseName.c_str(), CC_CALLBACK_1(HelloWorld::menuCallback, this));
        pItem->setTag(i);
        pItem->setPosition(Point(beginPos.x, beginPos.y - i * step));
        pMenu->addChild(pItem);
    }
    return true;
}
void MenuShopIntro::CreateMenuButtons()
{
    Point buttonPositions [kMenuShopIntroButtonButton_Max] =
    {
        Point(-70,-300),
        Point(70,-300),
    };
    
    const char* buttonUpImages [kMenuShopIntroButtonButton_Max] =
    {
        "res/ui/btn_yes.png",
        "res/ui/btn_no.png",
    };
    const char* buttonDownImages [kMenuShopIntroButtonButton_Max] =
    {
        "res/ui/btn_yes.png",
        "res/ui/btn_no.png",
    };
    
    ccMenuCallback buttonHandlers [kMenuShopIntroButtonButton_Max] =
    {
        CC_CALLBACK_1(MenuShopIntro::onBuyButtonCallback, this),
        CC_CALLBACK_1(MenuShopIntro::onSellButtonCallback, this),
    };
    
    MenuItemImage* tempButton;
    
    for (int i=0; i< kMenuShopIntroButtonButton_Max;++i)
    {
        tempButton = MenuItemImage::create(buttonUpImages[i],
                                           buttonDownImages[i],
                                           buttonHandlers[i]);
        tempButton->setPosition(buttonPositions[i]);
        m_pButtons[i] = tempButton;
    }
    
    for (int i=0;i<kMenuShopIntroButtonButton_Max;++i)
    {
        m_pMenu->addChild(m_pButtons[i]);
    }
}
Exemplo n.º 30
0
bool GameMain::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size size = Director::getInstance()->getWinSize();
    map = new GameObjMap();
    map->setAnchorPoint(Point(0,1));
    map->setPosition(Point(0,size.height));
    addChild(map,0);
    hero = new GameObjHero();
    //hero->setScale(0.5);
    //hero->setPosition(Point(100,160));
    hero->setPosition(Point(100,350));
    addChild(hero,1);
    gamemark = new GameMark();
    addChild(gamemark,4);
    gamemark = new GameMark();
    addChild(gamemark,4);
    gameover = Sprite::create("gameover.png");
    gameover->setAnchorPoint(Point(0.5,0.5));
    gameover->setPosition(Point(0,0));
    gameover->setPosition(Point(size.width/2,size.height/2 + 70));
    gameover->setVisible(false);
    //gameover->setScale(0.5);
    addChild(gameover,5);
    MenuItemImage *pCloseItem = MenuItemImage::create("back.png","back.png",CC_CALLBACK_1(GameMain::menuBackCallback, this));
    pCloseItem->setPosition( Point(size.width/2,size.height/2 - 50) );
    pCloseItem->setScale(0.5);
    Menu* pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition( Point::ZERO);
    this->addChild(pMenu,5,25);
    pMenu->setVisible(false);
    pMenu->setEnabled(false);
    isover = false;
    scheduleUpdate();
    return true;
}