cocos assert失败managere更新失败进去不去游戏

cocos2dx 3.1.1 在线热更新 自动更新(使用AssetsManager更新游戏资源包)
为什么要在线更新资源和脚本文件?
简单概括,如果你的游戏项目已经在google play 或Apple Store 等平台上架了,那么当你项目需要做一些活动或者修改前端的一些代码等那么你需要重新提交一个新版本给平台。但是平台审核和具体的上架时间是个不确定的。具体什么时候能上架,主要由具体的平台决定。
如果游戏项目是使用脚本语言进行编写的(如lua、js),那么一旦需要更新,则可以通过从服务器下载最新的脚本和资源,从而跳过平台直接实现在线更新。(有些平台是禁止在线更新资源方式的,但是你懂得)
闲话少说,本文主要是解决如何在项目中实现在线更新:
我们这里用的是cocos2dx的类AssertsMananger,它在引擎的extensions\assets-manager可以看到。
AssetsManager传三个参数,资源的zip包路径,version路径,写文件的路径。
然后调用AssetsManager的update函数进行下载更新。
设置资源包名称
这里继续沿用cocos2dx的AssetsManager类中默认的名称:cocos2dx-update-temp-package.zip。
如果想要修改文件名,可以直接修改引擎下 extensions\assets-manager\AsetsManager.ccp中的TEMP_PACKAGE_FILE_NAME
选定服务器地址和设置版本号 vc3Ryb25nPgogztLV4sDv08O1xMrHss6/vNfKwc/Su6OsTmVsc7XEuPbIy7/VvOSjqLKpv8212Na3aHR0cDovL3d3dy41OHBsYXllci5jb20vYmxvZy0yNTM3LTk1OTEzLmh0bWyjqcv7tcTXytS0sPzCt762us2xvrDmusWhoyAKIGh0dHA6Ly9zaGV6emVyLnNpbmFhcHAuY29tL2Rvd25sb2FkVGVzdC9jb2NvczJkeC11cGRhdGUtdGVtcC1wYWNrYWdlLnppcCA8YnI+CiBodHRwOi8vc2hlenplci5zaW5hYXBwLmNvbS9kb3dubG9hZFRlc3QvdmVyc2lvbi5waHAgIAo8YnI+Cgo8YnI+CjxzdHJvbmc+QyYjNDM7JiM0Mzu0+sLryrXP1jwvc3Ryb25nPjxicj4K0MK9qFVwZ3JhZGXA4KOsvMyz0NfUQ0NMYXllcgqx4LytVXBncmFkZS5ozsS8/sTayN3I58/Co7oKPGJyPgo8cHJlIGNsYXNzPQ=="brush:">//
Created by Sharezer on 14-11-23.
#ifndef _UPGRADE_H_
#define _UPGRADE_H_
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
class Upgrade : public cocos2d::CCLayer, public cocos2d::extension::AssetsManagerDelegateProtocol
Upgrade();
virtual ~Upgrade();
virtual bool init();
void upgrade(cocos2d::Ref* pSender); //检查版本更新
void reset(cocos2d::Ref* pSender);
//重置版本
virtual void onError(cocos2d::extension::AssetsManager::ErrorCode errorCode);
//错误信息
virtual void onProgress(int percent); //更新下载进度
virtual void onSuccess();
//下载成功
CREATE_FUNC(Upgrade);
cocos2d::extension::AssetsManager* getAssetManager();
void initDownloadDir();
//创建下载目录
std::string _pathToS
cocos2d::Label *_showDownloadI
修改Upgrade.cpp文件如下:
//Upgrade.cpp
#include "Upgrade.h"
#include "CCLuaEngine.h"
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
USING_NS_CC;
USING_NS_CC_EXT;
#define DOWNLOAD_FIEL
"download" //下载后保存的文件夹名
Upgrade::Upgrade():
_pathToSave(""),
_showDownloadInfo(NULL)
Upgrade::~Upgrade()
AssetsManager* assetManager = getAssetManager();
CC_SAFE_DELETE(assetManager);
bool Upgrade::init()
if (!CCLayer::init())
Size winSize = Director::getInstance()->getWinSize();
initDownloadDir();
_showDownloadInfo = Label::createWithSystemFont("", "Arial", 20);
this->addChild(_showDownloadInfo);
_showDownloadInfo->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 20));
auto itemLabel1 = MenuItemLabel::create(
Label::createWithSystemFont("Reset", "Arail", 20), CC_CALLBACK_1(Upgrade::reset, this));
auto itemLabel2 = MenuItemLabel::create(
Label::createWithSystemFont("Upgrad", "Arail", 20), CC_CALLBACK_1(Upgrade::upgrade, this));
auto menu = Menu::create(itemLabel1, itemLabel2, NULL);
this->addChild(menu);
itemLabel1->setPosition(Vec2(winSize.width / 2, winSize.height / 2 + 20));
itemLabel2->setPosition(Vec2(winSize.width / 2, winSize.height / 2 ));
menu->setPosition(Vec2::ZERO);
void Upgrade::onError(AssetsManager::ErrorCode errorCode)
if (errorCode == AssetsManager::ErrorCode::NO_NEW_VERSION)
_showDownloadInfo->setString("no new version");
else if (errorCode == AssetsManager::ErrorCode::NETWORK)
_showDownloadInfo->setString("network error");
else if (errorCode == AssetsManager::ErrorCode::CREATE_FILE)
_showDownloadInfo->setString("create file error");
void Upgrade::onProgress(int percent)
if (percent setString(progress);
void Upgrade::onSuccess()
CCLOG("download success");
_showDownloadInfo->setString("download success");
std::string path = FileUtils::getInstance()->getWritablePath() + DOWNLOAD_FIEL;
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
if (engine->executeScriptFile("src/main.lua")) {
AssetsManager* Upgrade::getAssetManager()
static AssetsManager *assetManager = NULL;
if (!assetManager)
assetManager = new AssetsManager("/downloadTest/cocos2dx-update-temp-package.zip",
"/downloadTest/version.php",
_pathToSave.c_str());
assetManager->setDelegate(this);
assetManager->setConnectionTimeout(8);
return assetM
void Upgrade::initDownloadDir()
CCLOG("initDownloadDir");
_pathToSave = CCFileUtils::getInstance()->getWritablePath();
_pathToSave += DOWNLOAD_FIEL;
CCLOG("Path: %s", _pathToSave.c_str());
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
DIR *pDir = NULL;
pDir = opendir(_pathToSave.c_str());
if (!pDir)
mkdir(_pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
if ((GetFileAttributesA(_pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES)
CreateDirectoryA(_pathToSave.c_str(), 0);
CCLOG("initDownloadDir end");
void Upgrade::reset(Ref* pSender)
_showDownloadInfo->setString("");
// Remove downloaded files
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
string command = "rm -r ";
// Path may include space.
command += "\"" + _pathToSave + "\"";
system(command.c_str());
std::string command = "rd /s /q ";
// Path may include space.
command += "\"" + _pathToSave + "\"";
system(command.c_str());
getAssetManager()->deleteVersion();
initDownloadDir();
void Upgrade::upgrade(Ref* pSender)
_showDownloadInfo->setString("");
getAssetManager()->update();
其中 Upgrade::onSuccess()函数中,我这里调用的是main.lua文件
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
if (engine->executeScriptFile("src/main.lua")) {
}如果是c++项目,可以自己调用相应的C++文件。
#include "HelloWorldScene.h"
auto scene = HelloWorld::scene();
Director::getInstance()->replaceScene(scene);
修改AppDelegate.cpp文件调用Upgrade类
AppDelegate.h无需修改,cpp稍微修改一下就可以了
头文件中加入#include "Upgrade.h"
主要是修改了AppDelegate::applicationDidFinishLaunching()函数中调用Upgrade类
#include "AppDelegate.h"
#include "CCLuaEngine.h"
#include "SimpleAudioEngine.h"
#include "cocos2d.h"
#include "Upgrade.h"
using namespace CocosD
USING_NS_CC;
AppDelegate::AppDelegate()
AppDelegate::~AppDelegate()
SimpleAudioEngine::end();
bool AppDelegate::applicationDidFinishLaunching()
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::createWithRect("dragan", Rect(0,0,900,640));
director->setOpenGLView(glview);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
//auto engine = LuaEngine::getInstance();
//ScriptEngineManager::getInstance()->setScriptEngine(engine);
//if (engine->executeScriptFile("src/main.lua")) {
auto scene = Scene::create();
auto layer =
Upgrade::create();
Director::getInstance()->runWithScene(scene);
scene->addChild(layer);
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
Director::getInstance()->stopAnimation();
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
Director::getInstance()->startAnimation();
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
修改cocos2dx的main.lua
我只是把其中一个资源文件名字和路径参考下载资源包中的路径修改了,以便看到资源更新的效果。
例如我把农场背景图片改为了下载资源包中的3D/CompleteMap.PNG
编译运行项目:
Reset:用于重置版本号,办删除下载资源。
Upgrad:校验版本号,当有更新时下载新资源。
_pathToSave保存着文件的下载路径,压缩包下载下来后,将被自动解压到_pathToSave中。
以win32为例,下载的资源是保存在Debug.win32\ 中,可以看到我们之前设置的下载目录download。
onSuccess中,当下载成功后,将跳转到main.lua中。
这时可以看到该文件已经直接使用已下载的资源。
______________________________________________________________________________
/blog-.html
Nels的个人空间
3.2引擎版本 lua热更新 自动更新
http://zengrong.net/post/2131.htm
这个关于lua热更新的文章也是写得甚好!十分容易明白,步骤清晰
http://blog.csdn.net/xiaominghimi/article/details/8825524
Himi关于热更新的解析贴
cocos2dx 2.x引擎版本
http://blog.csdn.net/cloud95/article/details/
cocos2dx lua热更新 实例版本,语言貌似比较通俗
/bbs/simple/?t183552.html
cocos关于热更新的讨论帖(关于路径的讨论很经典)
/bbs/read.php?tid=213066
cocos2dx lua 游戏热更新
http://lcinx./blog/static//
http://my.oschina.net/u/1785418/blog/283043
基于Quick-cocos2dx 2.2.3 的动态更新实现完整篇。(打包,服务器接口,模块自更新)
http://blog.csdn.net/q/article/details/8463835
lua热更新原理
http://lcinx./blog/static//
lua 热更新原理
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'Pages: 1/2
主题 : 关于热更新问题
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
关于热更新问题&&&
热更新,我使用AssertManager,有以下问题:更新下载zip包解压之后,解压文件怎么放到原来的游戏包里?在win下,替换和添加文件都没问题,因为游戏没有打包,但是在真机下该咋整?游戏apk包安装之后在data/app文件夹下找到了apk包,游戏跑的时候也跑的这个包,这个包里的文件可以改动吗?求帮助!!!!!!!!!!!!
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
游戏打包成apk之后如何进行热更新?求大神解答
级别: 侠客
UID: 248378
可可豆: 510 CB
威望: 331 点
在线时间: 170(时)
发自: Web Page
包里的文件是不可以改动的。Android也好,ios也好,在系统可写部分都是有空间的。热更新的部分是要放在可读写的地方,可以通过 CCFileUtils::sharedFileUtils()-&getWritablePath() 来获取它。
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
回 2楼(shujun.qiao) 的帖子
热更新的部分,我是放到可读写区域了,我也是用你说的方法获取的,但是这个路径仅仅是存放我本地文件的地方啊,我的游戏脚本都在apk里呢,我要更新脚本,必然要修改apk里的脚本啊。难道说我的更新思路不对么?
级别: 骑士
可可豆: 760 CB
威望: 761 点
在线时间: 151(时)
发自: Web Page
回 3楼(i-feel) 的帖子
你的思路有问题……加载路径是优先级的,先加载更新的路径,如果没有,才会去加载apk里面的……如果你想直接修改apk,而不是存有两个版本的文件,这还真的没办法了,除非发布一个新的apk更新,不过这样子就不需要assetmanager了说……
级别: 侠客
UID: 248378
可可豆: 510 CB
威望: 331 点
在线时间: 170(时)
发自: Web Page
修改apk里的脚本是做不到的。每修改一次apk,都要重新生成,并下载安装的。这不是热更新。是下载更新。热更新的文件,是要放到可写区域,这样每次更新,替换可写目录的同名文件,增加新文件,这样更新就会起效。
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
回 4楼(qq) 的帖子
比如说我游戏里的data.lua脚本需要更新,用AssertManager下载补丁包,解压出来data.lua文件后就放在CCFileUtils::sharedFileUtils()-&getWritablePath()路径下,和apk中的文件位置一致,apk中的data.lua没有修改,apk一点没动apk路径与更新文件路径如下:data/app/xxxx.apkdata/data/com.app.game.xxxx(这个路径是通过CCFileUtils::sharedFileUtils()-&getWritablePath()得到的)那么在启动游戏的时候,在游戏运行期间,如果我用到data.lua文件了,就会优先去搜索下面那个路径吗?如果是的话,就太感谢你了,我的问题就解决了,如果不是,我继续研究。求告知又有一个新的问题,这个路径的优先级是我自己设置的还是Android系统自带的路径优先级?[ 此帖被i-feel在 15:33重新编辑 ]
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
级别: 圣骑士
可可豆: 939 CB
威望: 1092 点
在线时间: 539(时)
发自: Web Page
哎,楼上回答问题都没有说到点子上,真让人捉急
专黑cocos三十年。cocos系列的坑连起来可以绕地球32圈哦~
级别: 侠客
UID: 266272
可可豆: 215 CB
威望: 216 点
在线时间: 87(时)
发自: Web Page
回 8楼(职业吐槽) 的帖子
谢谢指点,增加搜索路径是吧。是这样的,我的所有游戏代码都是用脚本写的,C++只提供了一个运行入口,就像Lua例子中的HelloWorld一样。也就是说如果我在C++代码里加了两个搜索路径,热更新目录的路径优先级比apk路径的优先级要高,那么在lua脚本中跑的时候,也会去优先搜索热更新目录吗?我的意思是在C++代码中优先设置好搜索路径,在脚本中跑游戏的时候,这个用到的脚本文件和资源文件还会按照路径的优先级来进行搜索吗?如果是的话,我的问题就解决了,不是的话,我就继续研究了。
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版2433人阅读
cocos2dx 3.1.1(lua)(28)
cocos2d-x 3.1.1(C++)(19)
为什么要在线更新资源和脚本文件?
简单概括,如果你的游戏项目已经在google play 或Apple Store 等平台上架了,那么当你项目需要做一些活动或者修改前端的一些代码等那么你需要重新提交一个新版本给平台。但是平台审核和具体的上架时间是个不确定的。具体什么时候能上架,主要由具体的平台决定。
如果游戏项目是使用脚本语言进行编写的(如lua、js),那么一旦需要更新,则可以通过从服务器下载最新的脚本和资源,从而跳过平台直接实现在线更新。(有些平台是禁止在线更新资源方式的,但是你懂得)
闲话少说,本文主要是解决如何在项目中实现在线更新:
我们这里用的是cocos2dx的类AssertsMananger,它在引擎的extensions\assets-manager可以看到。
AssetsManager传三个参数,资源的zip包路径,version路径,写文件的路径。
然后调用AssetsManager的update函数进行下载更新。
设置资源包名称&
这里继续沿用cocos2dx的AssetsManager类中默认的名称:cocos2dx-update-temp-package.zip。&&
&如果想要修改文件名,可以直接修改引擎下&extensions\assets-manager\AsetsManager.ccp中的TEMP_PACKAGE_FILE_NAME&
&&&&&&&&&&
选定服务器地址和设置版本号&
&我这里用的是参考资料一,Nels的个人空间(博客地址/blog-.html)他的资源包路径和本版号。&
&/downloadTest/cocos2dx-update-temp-package.zip&
&/downloadTest/version.php&&
C++代码实现
新建Upgrade类,继承自CCLayer
编辑Upgrade.h文件内容如下:
Created by Sharezer on 14-11-23.
#ifndef _UPGRADE_H_
#define _UPGRADE_H_
#include &cocos2d.h&
#include &extensions/cocos-ext.h&
class Upgrade : public cocos2d::CCLayer, public cocos2d::extension::AssetsManagerDelegateProtocol
Upgrade();
virtual ~Upgrade();
virtual bool init();
void upgrade(cocos2d::Ref* pSender); //检查版本更新
void reset(cocos2d::Ref* pSender);
//重置版本
virtual void onError(cocos2d::extension::AssetsManager::ErrorCode errorCode);
//错误信息
virtual void onProgress(int percent); //更新下载进度
virtual void onSuccess();
//下载成功
CREATE_FUNC(Upgrade);
cocos2d::extension::AssetsManager* getAssetManager();
void initDownloadDir();
//创建下载目录
std::string _pathToS
cocos2d::Label *_showDownloadI
修改Upgrade.cpp文件如下:
//Upgrade.cpp
#include &Upgrade.h&
#include &CCLuaEngine.h&
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
#include &dirent.h&
#include &sys/stat.h&
USING_NS_CC;
USING_NS_CC_EXT;
#define DOWNLOAD_FIEL
&download& //下载后保存的文件夹名
Upgrade::Upgrade():
_pathToSave(&&),
_showDownloadInfo(NULL)
Upgrade::~Upgrade()
AssetsManager* assetManager = getAssetManager();
CC_SAFE_DELETE(assetManager);
bool Upgrade::init()
if (!CCLayer::init())
Size winSize = Director::getInstance()-&getWinSize();
initDownloadDir();
_showDownloadInfo = Label::createWithSystemFont(&&, &Arial&, 20);
this-&addChild(_showDownloadInfo);
_showDownloadInfo-&setPosition(Vec2(winSize.width / 2, winSize.height / 2 - 20));
auto itemLabel1 = MenuItemLabel::create(
Label::createWithSystemFont(&Reset&, &Arail&, 20), CC_CALLBACK_1(Upgrade::reset, this));
auto itemLabel2 = MenuItemLabel::create(
Label::createWithSystemFont(&Upgrad&, &Arail&, 20), CC_CALLBACK_1(Upgrade::upgrade, this));
auto menu = Menu::create(itemLabel1, itemLabel2, NULL);
this-&addChild(menu);
itemLabel1-&setPosition(Vec2(winSize.width / 2, winSize.height / 2 + 20));
itemLabel2-&setPosition(Vec2(winSize.width / 2, winSize.height / 2 ));
menu-&setPosition(Vec2::ZERO);
void Upgrade::onError(AssetsManager::ErrorCode errorCode)
if (errorCode == AssetsManager::ErrorCode::NO_NEW_VERSION)
_showDownloadInfo-&setString(&no new version&);
else if (errorCode == AssetsManager::ErrorCode::NETWORK)
_showDownloadInfo-&setString(&network error&);
else if (errorCode == AssetsManager::ErrorCode::CREATE_FILE)
_showDownloadInfo-&setString(&create file error&);
void Upgrade::onProgress(int percent)
if (percent & 0)
char progress[20];
snprintf(progress, 20, &download %d%%&, percent);
_showDownloadInfo-&setString(progress);
void Upgrade::onSuccess()
CCLOG(&download success&);
_showDownloadInfo-&setString(&download success&);
std::string path = FileUtils::getInstance()-&getWritablePath() + DOWNLOAD_FIEL;
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()-&setScriptEngine(engine);
if (engine-&executeScriptFile(&src/main.lua&)) {
AssetsManager* Upgrade::getAssetManager()
static AssetsManager *assetManager = NULL;
if (!assetManager)
assetManager = new AssetsManager(&/downloadTest/cocos2dx-update-temp-package.zip&,
&/downloadTest/version.php&,
_pathToSave.c_str());
assetManager-&setDelegate(this);
assetManager-&setConnectionTimeout(8);
return assetM
void Upgrade::initDownloadDir()
CCLOG(&initDownloadDir&);
_pathToSave = CCFileUtils::getInstance()-&getWritablePath();
_pathToSave += DOWNLOAD_FIEL;
CCLOG(&Path: %s&, _pathToSave.c_str());
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
DIR *pDir = NULL;
pDir = opendir(_pathToSave.c_str());
if (!pDir)
mkdir(_pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
if ((GetFileAttributesA(_pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES)
CreateDirectoryA(_pathToSave.c_str(), 0);
CCLOG(&initDownloadDir end&);
void Upgrade::reset(Ref* pSender)
_showDownloadInfo-&setString(&&);
// Remove downloaded files
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
string command = &rm -r &;
// Path may include space.
command += &\&& + _pathToSave + &\&&;
system(command.c_str());
std::string command = &rd /s /q &;
// Path may include space.
command += &\&& + _pathToSave + &\&&;
system(command.c_str());
getAssetManager()-&deleteVersion();
initDownloadDir();
void Upgrade::upgrade(Ref* pSender)
_showDownloadInfo-&setString(&&);
getAssetManager()-&update();
其中&Upgrade::onSuccess()函数中,我这里调用的是main.lua文件
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()-&setScriptEngine(engine);
if (engine-&executeScriptFile(&src/main.lua&)) {
}如果是c++项目,可以自己调用相应的C++文件。
如& #include&&HelloWorldScene.h&
auto&scene&=&HelloWorld::scene();
Director::getInstance()-&replaceScene(scene);
修改AppDelegate.cpp文件调用Upgrade类
AppDelegate.h无需修改,cpp稍微修改一下就可以了
头文件中加入#include &Upgrade.h&
主要是修改了AppDelegate::applicationDidFinishLaunching()函数中调用Upgrade类&
#include &AppDelegate.h&
#include &CCLuaEngine.h&
#include &SimpleAudioEngine.h&
#include &cocos2d.h&
#include &Upgrade.h&
using namespace CocosD
USING_NS_CC;
AppDelegate::AppDelegate()
AppDelegate::~AppDelegate()
SimpleAudioEngine::end();
bool AppDelegate::applicationDidFinishLaunching()
// initialize director
auto director = Director::getInstance();
auto glview = director-&getOpenGLView();
if(!glview) {
glview = GLView::createWithRect(&dragan&, Rect(0,0,900,640));
director-&setOpenGLView(glview);
glview-&setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS
director-&setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director-&setAnimationInterval(1.0 / 60);
//auto engine = LuaEngine::getInstance();
//ScriptEngineManager::getInstance()-&setScriptEngine(engine);
//if (engine-&executeScriptFile(&src/main.lua&)) {
auto scene = Scene::create();
auto layer =
Upgrade::create();
Director::getInstance()-&runWithScene(scene);
scene-&addChild(layer);
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
Director::getInstance()-&stopAnimation();
SimpleAudioEngine::getInstance()-&pauseBackgroundMusic();
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
Director::getInstance()-&startAnimation();
SimpleAudioEngine::getInstance()-&resumeBackgroundMusic();
修改cocos2dx的main.lua
我只是把其中一个资源文件名字和路径参考下载资源包中的路径修改了,以便看到资源更新的效果。
例如我把农场背景图片改为了下载资源包中的3D/CompleteMap.PNG
编译运行项目:&
&&&&&&&&&&
&&&&&&&&Reset:用于重置版本号,办删除下载资源。&
&&&&&&&&Upgrad:校验版本号,当有更新时下载新资源。&
&&&&&&&&&&
&&&&&&&&_pathToSave保存着文件的下载路径,压缩包下载下来后,将被自动解压到_pathToSave中。&
&&&&&&&&以win32为例,下载的资源是保存在Debug.win32\&中,可以看到我们之前设置的下载目录download。&
&&&&&&&&onSuccess中,当下载成功后,将跳转到main.lua中。&&
&&&&&&&&这时可以看到该文件已经直接使用已下载的资源。&
&&&&&&&&&&
______________________________________________________________________________
/blog-.html &Nels的个人空间 &&cocos2dx
3.2引擎版本 lua热更新 自动更新&
http://zengrong.net/post/2131.htm &这个关于lua热更新的文章也是写得甚好!十分容易明白,步骤清晰
http://blog.csdn.net/xiaominghimi/article/details/8825524 &Himi关于热更新的解析贴 &cocos2dx 2.x引擎版本
http://blog.csdn.net/cloud95/article/details/ & cocos2dx lua热更新 实例版本,语言貌似比较通俗
/bbs/simple/?t183552.html &cocos关于热更新的讨论帖(关于路径的讨论很经典)
/bbs/read.php?tid=213066 & &cocos2dx lua 游戏热更新
http://lcinx./blog/static//
http://my.oschina.net/u/1785418/blog/283043 &&基于Quick-cocos2dx 2.2.3 的动态更新实现完整篇。(打包,服务器接口,模块自更新)
http://blog.csdn.net/q/article/details/8463835 &lua热更新原理
http://lcinx./blog/static// &&lua 热更新原理 &
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:138154次
积分:2514
积分:2514
排名:第11302名
原创:116篇
转载:15篇
评论:28条}

我要回帖

更多关于 cocos2d x assert 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信