首页 > 代码库 > wp上使用AssetsManager

wp上使用AssetsManager

不知道什么原因cocos2dx v2.2.5版本在AssetsManager.h和AssetsManager.cpp中增加

#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8)

这个宏直接关闭了AssetsManager,具体原因不得而知了,

不过鄙人发现通过修改是可以使用的,因为已经有了CCPThreadWinRT.h可以实现线程,

修改之,首先去掉那个无理由的宏定义

#include <pthread.h>这个是没有的,不过可以使用过来实现在wp上使用CCPThreadWinRT.h

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) ||  (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)#include "CCPThreadWinRT.h"typedef void THREAD_VOID;#define THREAD_RETURN#else#include <pthread.h>#endif

修改:startDownload

 1 void AssetsManager::startDownload() 2 { 3     // Is package already downloaded? 4     if (false == m_bIsFullUpdate) 5         _downloadedVersion = CCUserDefault::sharedUserDefault()->getStringForKey(KEY_OF_DOWNLOADED_VERSION); 6     else 7         _downloadedVersion = CCUserDefault::sharedUserDefault()->getStringForKey(KEY_OF_DOWNLOADED_UPDATE_VERSION); 8  9     _tid = new pthread_t();10 #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)11     pthread_create(&(*_tid), nullptr, std::bind(assetsManagerDownloadAndUncompress, (void*)this), (void*)this);12 #else13     pthread_create(&(*_tid), nullptr, assetsManagerDownloadAndUncompress, (void*)this);14 #endif15 }

修改:void* assetsManagerDownloadAndUncompress(void *data)函数最后一段

 1     if (self->_tid) 2     { 3 #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) 4         pthread_exit(self->_tid); 5 #else 6         delete self->_tid; 7 #endif 8         self->_tid = NULL; 9     }10     

否则会crash,

这样基本就可以用了,线程可以用了。curl本身提供了wp版本的,

改到这里基本就可以使用AssetsManager了

GL

wp上使用AssetsManager