#ifndef __GAMEMAIN_SCENE_H__
#define __GAMEMAIN_SCENE_H__ #include "cocos2d.h" #include "Box2D/Box2D.h" #include "SimpleAudioEngine.h" #include "CocoHead.h"
#include "GameScene.h" class CCLayer; class CGameMainScene : public CGameScene
{
public:
enum ResourceID
{
_ResourceId = ,
}; enum MainSceneId
{
_IDD_MainSceneDialog = , _IDC_MainSceneBg = ,
};
public:
CGameMainScene();
virtual ~CGameMainScene(); CREATE_SCENE(CGameMainScene); // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
virtual bool initRes(); // a selector callback
void menuCloseCallback(CCObject* pSender); void menuMsgCallback(CCObject* pSender); protected:
virtual void update(float dt); virtual void onEnter();
virtual void onExit(); private:
CCLayer* m_pLayerBg;
CCLayer* m_pLayerInfo; }; #endif // __HELLOWORLD_SCENE_H__
#include "GameMainScene.h"
#include "WidgetMgr.h"
#include "Config.h"
#include "GameLogic.h"
#include "AudioMgr.h"
#include "MenuDialog.h"
#include "AboutDialog.h"
#include "SectsInfomation.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "GameCenter.h"
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) CGameMainScene::CGameMainScene()
{
m_pLayerBg = NULL;
m_pLayerInfo = NULL;
} CGameMainScene::~CGameMainScene()
{ } // on "init" you need to initialize your instance
bool CGameMainScene::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); //////////////////////////////////////////////////////////////////////////
// add your codes below...
////////////////////////////////////////////////////////////////////////// m_pLayerBg = CCLayer::create();
m_pLayerInfo = CCLayer::create(); this->addChild(m_pLayerBg, );
this->addChild(m_pLayerInfo, ); bRet = true;
} while (); return bRet;
} void CGameMainScene::update( float dt )
{ } void CGameMainScene::menuMsgCallback( CCObject* pSender )
{ } void CGameMainScene::onEnter()
{
CGameScene::onEnter(); this->initRes();
} bool CGameMainScene::initRes()
{
bool bRet = false; CCSprite* pBg = CCSprite::create(CConfig::getInstance()->getImageInfoById()->strFile.c_str());
pBg->setAnchorPoint(ccp(, ));
m_pLayerBg->addChild(pBg, , ); CREATE_DIALOG(CMenuDialog, m_pLayerInfo, );
CREATE_DIALOG(CAboutDialog, m_pLayerInfo, );
//CREATE_DIALOG(CSectsInfomation, m_pLayerInfo, 0); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
GameCenter::getInstance()->authenticateLocalUser();
#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) CGameLogic::getInstance()->readConfiguration(); if (CGameLogic::getInstance()->getConfiguration()->bBackgroundMusic)
{
CAudioMgr::getInstance()->player("backgroundmusic_01", true);
} CGameLogic::getInstance()->setLevel(_Level_xmb); bRet = true;
return bRet;
} void CGameMainScene::onExit()
{
CGameScene::onExit(); this->removeFromParentAndCleanup(true);
CWidgetMgr::getInstance()->clearAllWnd(); //CWidgetMgr::destroy();
}
05-11 22:37