溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

cocos2dx3.2格斗類游戲加載界面

發(fā)布時間:2020-06-19 00:00:08 來源:網(wǎng)絡 閱讀:749 作者:上官曉琪 欄目:編程語言

先看效果圖:

cocos2dx3.2格斗類游戲加載界面

cocos2dx3.2格斗類游戲加載界面

cocos2dx使用版本:cocos2dx3.2   IDE:使用VS2013

下載游戲引擎自不用說了。

使用命令行創(chuàng)建項目。

cocos new GeDou -p com.zhenqi.game -l cpp -d F:\cocos2d-xProject

而后使用vs2013打開,并創(chuàng)建一個加載層。

LoadingScene.h 內(nèi)容如下:
#ifndef __LOADING_SCENE_H__
#define __LOADING_SCENE_H__
#include "ui/CocosGUI.h"
#include "cocos2d.h"
USING_NS_CC;
class Loading : public Layer
{
public:
static Scene* createScene();
virtual bool init();
//設置進度條
void SetPro(float fRate);
//資源預加載
void LoadRec();
//資源預加載回調(diào)函數(shù)
void OnLoadArmatureData(float percent);
//資源加載回調(diào)
void OnLoadRecCallBack(Object *pObj);
    CREATE_FUNC(Loading);
protected:
intm_nLoadRecNum;//資源加載數(shù)
intm_nLoadRecTotalNum;//資源加載總數(shù)
ui::LoadingBar* pProLoadRec;    //進度條
};
#endif // __LOADING_SCENE_H__

LoadingScene.cpp 實現(xiàn)類如下:

#include "LoadingScene.h"
#include "ChooseHero.h"
#include "ui/CocosGUI.h"
#include "cocostudio/CocoStudio.h"
using namespace cocostudio;
Scene* Loading::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = Loading::create();
    // add layer as a child to scene
    scene->addChild(layer);
    // return the scene
    return scene;
}
bool Loading::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getWinSize();
/************************************************************************/
/*背景圖片                                                */
/************************************************************************/
//人物圖片
auto pPersonBg = Sprite::create("ui/loading_bg.png");
pPersonBg->setPosition(ccp(size.width*0.5f, size.height*0.5f));
addChild(pPersonBg, 100);
//創(chuàng)建logo圖
auto pLogo = Sprite::create("ui/logo_bg.png");
pLogo->setScale(0.95f);
pLogo->setPosition(ccp(size.width*0.5f, 410));
addChild(pLogo, 100);
/************************************************************************/
/*進度條                                                  */
/************************************************************************/
//創(chuàng)建加載進度條背景
auto pProBg = Sprite::create("ui/loading_progress_bg.png");
pProBg->setPosition(ccp(size.width*0.5f, 100));
addChild(pProBg, 100000);
pProLoadRec = ui::LoadingBar::create("ui/loading_progress_bar.png");
pProLoadRec->setPosition(pProBg->getPosition());
pProLoadRec->setDirection(ui::LoadingBar::Direction::LEFT);
pProLoadRec->setPercent(0);
addChild(pProLoadRec, 100001, 1);//同時設置Tag值為1
auto pLight = Sprite::create("ui/loading_progress_light.png");
addChild(pLight, 300000, 2);
pLight->setPosition(ccp(pProLoadRec->getPositionX() - pProLoadRec->getContentSize().width*0.5f, pProLoadRec->getPositionY()));
m_nLoadRecNum = 0;
m_nLoadRecTotalNum = 16;
//預加載本層資源
LoadRec();
    
    return true;
}
void Loading::SetPro(float fRate)
{
do
{
pProLoadRec->setPercent(fRate * 100);
//同步光點
auto pLight = dynamic_cast<Sprite *>(getChildByTag(2));
if (pLight != NULL)
pLight->setPositionX(pProLoadRec->getPositionX() + pProLoadRec->getContentSize().width*(fRate - 0.5f));
//若加載完成
if (fRate >= 1)
{
auto pDicLang = Dictionary::createWithContentsOfFile("ui_xml/loading_xml.xml");
//得到加載信息label
auto pStrLoading = dynamic_cast<String*>(pDicLang->objectForKey("loading_end"));
auto pLabelLoading = dynamic_cast<LabelTTF *>(getChildByTag(3));
//pLabelLoading->setString(pStrLoading->getCString());
}
return;
} while (false);
//CCLog("Fun CNFLoadingLayer::SetPro Error!");
}
//資源預加載
void Loading::LoadRec()
{
TextureCache::getInstance()->addImageAsync("ui/serverselect_bg.png", CC_CALLBACK_1(Loading::OnLoadRecCallBack,this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/kulougongshou.ExportJson",this,schedule_selector(Loading::OnLoadArmatureData,this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/kulouzhanshi.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/mayi.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bianyikunchong.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bubing.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/xiaoyin.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/NewProject.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/minren1.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/kulou_arrow.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/naili.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/NPC_kakaxi.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/portal.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/hited_light.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/public_casting.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/skill_light_1.ExportJson", this, schedule_selector(Loading::OnLoadArmatureData, this));
}
void Loading::OnLoadArmatureData(float percent){
m_nLoadRecNum++;
SetPro((float)m_nLoadRecNum / (float)m_nLoadRecTotalNum);
if (m_nLoadRecNum == m_nLoadRecTotalNum){
//延遲1秒
//Director::getInstance()->replaceScene(ChooseHero::createScene());

}
if (percent >= 1)
{
//CCLog("addArmatureFileInfoAsync over");
}
}
void Loading::OnLoadRecCallBack(Object *pObj){
do
{
m_nLoadRecNum++;
SetPro((float)m_nLoadRecNum / (float)m_nLoadRecTotalNum);
if (m_nLoadRecNum == m_nLoadRecTotalNum){
//延遲1秒
//Director::getInstance()->replaceScene(ChooseHero::createScene());

}
return;
} while (false);
//CCLog("Fun CNFLoginScene::OnLoadRecCallBack Error!");
}


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI