#ifndef __LOADSCENE_H__
#define __LOADSCENE_H__
#include "GameFrameHead.h"
class CGameScene;
class CLoadScene : public cocos2d::CCLayer
{
public:
enum PmgressbarId
{
_PmgressbarDialog = ,
_PmgressbarPic = ,
};
public:
CLoadScene();
virtual ~CLoadScene(void);
static CCScene* create();
bool init();
public:
//加载资源
void loadRes();
//读进度回调函数
//void loadingCallBack(CCObject *obj);
protected:
void replaceMainlScene();
//场景放到这里创建
//把创建的场景加到场景管理器中
// 内部使用,外部不要调用
void initRes();
private:
CCLayer* m_pProgressLayer;
CCSprite* m_pPicLoadBG; //进度条背景
CCSprite* m_pPicBg; //界面背景图
CCProgressTimer* m_pProTimeBar; //进度条
int m_nNumberOfSprites;
int m_nNumberOfLoadedSprites;
};
#endif //__LOADSCENE_H__
#include "LoadScene.h"
#include "GameScene.h"
#include "XSprite.h"
#include "Config.h"
#include "WidgetMgr.h"
#include "SplashScene.h"
#include "XImage.h"
#include "XWidget.h"
#include "GameMainScene.h"
#include "GameConfig.h"
#include "GameLogic.h"
//#include "SplashLoading.h"
#include "GameLevelScene.h"
CLoadScene::CLoadScene()
{
m_pPicLoadBG = NULL;
m_pPicBg = NULL;
m_nNumberOfLoadedSprites = ;
m_nNumberOfSprites = ;
m_pProTimeBar = NULL;
}
CLoadScene::~CLoadScene(void)
{
CCLOG("CLoadScene::~CLoadScene");
}
CCScene* CLoadScene::create()
{
CCScene* pScene = CCScene::create();
CLoadScene* pLoadScene = new CLoadScene();
if (pScene && pLoadScene)
{
pLoadScene->init();
pScene->addChild(pLoadScene,);
pLoadScene->autorelease();
}
return pScene;
}
bool CLoadScene::init()
{
//读取配置
CConfig::getInstance()->loadImageInfo();
CConfig::getInstance()->loadElementInfo();
CConfig::getInstance()->loadWidgetInfo();
CConfig::getInstance()->loadAnimationInfo();
CConfig::getInstance()->loadSrollInfo();
CConfig::getInstance()->loadEffectInfo();
CConfig::getInstance()->loadAudioInfo();
CConfig::getInstance()->loadWordInfo();
CConfig::getInstance()->loadActionInfo();
CConfig::getInstance()->loadNumberInfo();
CGameConfig::getInstance()->loadMapInfo();
CGameConfig::getInstance()->loadBiontInfo();
CGameConfig::getInstance()->loadWeaponInfo();
CGameConfig::getInstance()->loadSectInfo();
CGameLogic::getInstance()->readSaveData();
//初始化元素 把plist形式的图片资源加载到内存
vector<PlistInfo>* vecPlist = CConfig::getInstance()->getElementInfoByItem();
if (vecPlist)
{
for (vector<PlistInfo>::iterator it = vecPlist->begin(); it != vecPlist->end(); it++)
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(it->strPlist.c_str(), it->strImage.c_str());
}
}
vector<PlistInfo>* vecPlist1 = CConfig::getInstance()->getElementInfoByItem();
if (vecPlist1)
{
for (vector<PlistInfo>::iterator it = vecPlist1->begin(); it != vecPlist1->end(); it++)
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(it->strPlist.c_str(), it->strImage.c_str());
}
}
////进度条界面
//CXWidget* pPmgressDlg = new CXWidget;
//CWidgetMgr::getInstance()->loadWidget(pPmgressDlg, _PmgressbarDialog);
//pPmgressDlg->autorelease();
//this->addChild(pPmgressDlg);
//
//pPmgressDlg->getCtrl(_PmgressbarPic)->setVisible(false);
////进度条
//m_pProTimeBar = CCProgressTimer::create(((CXImage*)pPmgressDlg->getCtrl(_PmgressbarPic))->getPic());
//if (m_pProTimeBar)
//{
// m_pProTimeBar->setPosition(pPmgressDlg->getCtrl(_PmgressbarPic)->getPosition());
// m_pProTimeBar->setType(kCCProgressTimerTypeBar);
// m_pProTimeBar->setMidpoint(ccp(0,0));
// m_pProTimeBar->setBarChangeRate(ccp(0.5,0));
// m_pProTimeBar->ignoreAnchorPointForPosition(true);
// //m_pProTimeBar->setAnchorPoint(ccp(0,0));
// this->addChild(m_pProTimeBar);
// CCSize size = CCDirector::sharedDirector()->getWinSize();
// CCProgressTo* pProgressTo = CCProgressTo::create(2,100);
// m_pProTimeBar->runAction(pProgressTo);
//}
this->loadRes();
return true;
}
//void CLoadScene::loadingCallBack( CCObject *obj )
//{
// ++m_nNumberOfLoadedSprites;//每调用一次就+1
//
// //全部加载完成后,就执行
// if (m_nNumberOfLoadedSprites == m_nNumberOfSprites)
// {
// //切换场景
// //加载完 延时2秒 切换场景
// CCDelayTime* pActDelay = CCDelayTime::create(2.0f);
// CCFiniteTimeAction* pAction = CCSequence::create(pActDelay,
// CCCallFunc::create(this, callfunc_selector(CLoadScene::replaceMainlScene)),
// NULL);
// m_pProgressLayer->runAction(pAction);
// }
//
//}
void CLoadScene::loadRes()
{
//把Plist文件加载到内存
CCDelayTime *delayAction = CCDelayTime::create(0.1f);
CCCallFunc *callSelectorAction = CCCallFunc::create(this,callfunc_selector(CLoadScene::replaceMainlScene));
this->runAction(CCSequence::create(delayAction, callSelectorAction, NULL));
}
void CLoadScene::replaceMainlScene()
{
//CSplashLoading* pSplashLoading = CSplashLoading::create(CGameMainScene::create(CGameMainScene::_ResourceId));
//pSplashLoading->retainPrevResource();
CCDirector::sharedDirector()->replaceScene(CSplashScene::create(CGameMainScene::create(CGameMainScene::_ResourceId)));
//CCDirector::sharedDirector()->replaceScene(CSplashScene::create(CGameLevelScene::create(CGameLevelScene::_ResourceId)));
}
void CLoadScene::initRes()
{
//这里初始化资源
}