Game Development Reference
In-Depth Information
_mainMenu = Menu::create(howToItem, starGametItem,
nullptr);
_mainMenu->alignItemsHorizontallyWithPadding(120);
_mainMenu->setPosition(Vec2(_screenSize.width *
0.5f, _screenSize.height * 0.54));
this->addChild(_mainMenu, kForeground);
The
Menu
constructor can receive as many
MenuItemSprite
objects as you
wish to display. These items are then distributed with one of the following calls:
alignItemsHorizontally
,
alignItemsHorizontallyWithPad-
ding
,
alignItemsHorizontally
,
alignItemsVertic-
allyWithPadding
,
alignItemsInColumns
, and
alignItem-
sInRows
. And the items appear in the order they are passed to the
Menu
con-
structor.
4. Then we need to add our callback functions:
void GameLayer::startGame (Ref* pSender) {
_tutorialLabel->setVisible(false);
_intro->setVisible(false);
_mainMenu->setVisible(false);
_jam->runAction(_jamMove);
SimpleAudioEngine::getInstance()
->playEffect("start.wav");
_terrain->setStartTerrain ( true );
_state = kGamePlay;
}
void GameLayer::showTutorial (Ref* pSender) {
_tutorialLabel->setString ("Tap the screen to make
the player jump.");
_state = kGameTutorialJump;
_jam->runAction(_jamMove);
_intro->setVisible(false);
_mainMenu->setVisible(false);
SimpleAudioEngine::getInstance()
->playEffect("start.wav");
_tutorialLabel->setVisible(true);