Cocos2d-x 3.x 异步加载资源和Loading界面

该博客详细介绍了如何在Cocos2d-x 3.x中实现异步加载图片和动画资源,并提供了一个加载界面的实现,通过动态加载技术提高游戏性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个异步加载图片资源和动画资源的ladoing界面。下面给代码

.h文件

#ifndef RUN_SCENE_LOADINGLAYER_H__
#define RUN_SCENE_LOADINGLAYER_H__


#include "cocos2d.h"


using namespace cocos2d;


class LoadingLayer : public Layer
{
public:
<span style="white-space:pre">	</span>LoadingLayer();
<span style="white-space:pre">	</span>~LoadingLayer();


<span style="white-space:pre">	</span>virtual bool init();
<span style="white-space:pre">	</span>CREATE_FUNC(LoadingLayer);
<span style="white-space:pre">	</span>virtual void onEnter();
<span style="white-space:pre">	</span>virtual void update(float dt);


<span style="white-space:pre">	</span>void AddImageCallBack(Texture2D *texture);<span style="white-space:pre">	</span>//加图片
<span style="white-space:pre">	</span>void AddAniCallBack(float dt);<span style="white-space:pre">				</span>//加动画
protected:
<span style="white-space:pre">	</span>std::vector<std::string> m_stvImageNames;<span style="white-space:pre">		</span>//所有要加载的图片名称
<span style="white-space:pre">	</span>std::vector<std::string> m_stvAniNames;<span style="white-space:pre">			</span>//所有要加载的动画名称
<span style="white-space:pre">	</span>std::vector<std::string> m_stvSpriteFrameName;<span style="white-space:pre">	</span>//所有要加载的大图名称
<span style="white-space:pre">	</span>ProgressTimer* m_pLoadingProress;<span style="white-space:pre">				</span>//进度条
<span style="white-space:pre">	</span>Label* m_pLoadingLabel;


<span style="white-space:pre">	</span>int m_iLoadingNum;
<span style="white-space:pre">	</span>float m_fPassTime;
<span style="white-space:pre">	</span>bool m_bImageHasLoading;
};


#endif // LOADINGLAYER_H__



.cpp

#include "LoadingLayer.h"
#include "GameScene.h"
#include "data\game_constant_defines.h"


LoadingLayer::LoadingLayer() : 
<span style="white-space:pre">	</span>m_pLoadingProress(nullptr),
<span style="white-space:pre"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值