newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#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 = 2,
    };

    enum MainSceneId
    {
        _IDD_MainSceneDialog = 101,

        _IDC_MainSceneBg = 10002,
    };
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, 1);
        this->addChild(m_pLayerInfo, 2);


        bRet = true;
    } while (0);

    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(10001)->strFile.c_str());
    pBg->setAnchorPoint(ccp(0, 0));
    m_pLayerBg->addChild(pBg, 0, 10001);
    

    CREATE_DIALOG(CMenuDialog, m_pLayerInfo, 0);
    CREATE_DIALOG(CAboutDialog, m_pLayerInfo, 0);
    //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();
}

 

posted on 2013-07-03 21:07  一枚程序  阅读(764)  评论(0编辑  收藏  举报