场景和声音类都是套路了。。。
//窗口大小的设定:
//android下
//注意要放到if外:
glview->setDesignResolutionSize(,224,ResolutionPolicy::SHOW_ALL)
//windows下加:
glview->setFrameSize(640,224);
//改写HelloWorldScene,名字先改掉--WelcomeScene
//调整图片和文字的位置:
#include "WelcomeScene.h"
USING_NS_CC;
Scene* WelcomeScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = WelcomeScene::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool WelcomeScene::init()
{
//
// 1. super init first
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 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
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(WelcomeScene::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
origin.y + closeItem->getContentSize().height / 2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
/
auto Title = Sprite::create("title1.png");
Title->setAnchorPoint(ccp(0,0));
Title->setPosition((origin.x + visibleSize.width-Title->getContentSize().width) / 2, (origin.y + visibleSize.height-Title->getContentSize().height) * 2 / 3);
addChild(Title);
auto selectPlayer = CCLabelTTF::create("PLAYER SELECT", "Arial", 26);
selectPlayer->setAnchorPoint(Point::ZERO);
selectPlayer->setPosition((origin.x + Title->getPositionX()+64), Title->getPositionY()-32);
this->addChild(selectPlayer);
auto OnePlayer = CCLabelTTF::create("1 PLAYER", "Arial", 26);
auto MenuItemPlayer = MenuItemLabel::create(OnePlayer,this, menu_selector(WelcomeScene::callBackStart));
MenuItemPlayer->setAnchorPoint(ccp(0, 0));
MenuItemPlayer->setPosition((origin.x + selectPlayer->getPositionX()+10),selectPlayer->getPositionY() - 32);
auto TwoPlayer = CCLabelTTF::create("2 PLAYER", "Arial", 26);
auto MenuItemPlayer2 = MenuItemLabel::create(TwoPlayer, this, menu_selector(WelcomeScene::callBackStart2));
MenuItemPlayer2->setAnchorPoint(ccp(0, 0));
MenuItemPlayer2->setPosition((origin.x + selectPlayer->getPositionX() + 10), MenuItemPlayer->getPositionY() - 32);
Menu* menuPlayer = Menu::create(MenuItemPlayer, MenuItemPlayer2,NULL);
menuPlayer->setPosition(ccp(0, 0));
this->addChild(menuPlayer);
auto WelPlayer = Sprite::create("WelPlayer.png");
WelPlayer->setAnchorPoint(ccp(0,0));
WelPlayer->setPosition((origin.x + selectPlayer->getPositionX()+selectPlayer->getContentSize().width+10), selectPlayer->getPositionY()-64);
this->addChild(WelPlayer);
return true;
}
void WelcomeScene::callBackStart(Object *p)
{
//1 player scene;
}
void WelcomeScene::callBackStart2(Object *p)
{
}
void WelcomeScene::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
return;
#endif
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
声音类(初步,只在开始场景调用)
#include "Sounder.h"
Sounder *Sounder::shareSounder = NULL;
Sounder *Sounder::getInstance()
{
if (shareSounder == NULL)
{
shareSounder = new Sounder;
shareSounder->init();
}
return shareSounder;
}
bool Sounder::init() //忘了写Sounder导致fatal error LNK1120: 1 个无法解析的外部命令。。。。
{
SimpleAudioEngine::getInstance()->preloadBackgroundMusic(START_BG_MUSIC);
return true;
}
void Sounder::playStartBgMusic()
{
SimpleAudioEngine::getInstance()->playBackgroundMusic(START_BG_MUSIC);
}