Created
June 3, 2014 16:11
-
-
Save jake1256/34b9dee9c94a1aeaefdc to your computer and use it in GitHub Desktop.
【cocos2d-x v3.1】cocos2dxでzipファイルを扱う場合のまとめ。load timeの計測もあるよ。 ref: http://qiita.com/kuuki_yomenaio/items/b93b236ed5563adf9c39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char* buf = FileUtils::getInstance()->getFileDataFromZip( | |
path.c_str() , | |
zipFile.c_str(), | |
(ssize_t*)&size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 片方ずつ行います。(コメントアウトで簡単に) | |
void exec(){ | |
// resourceから読み出す | |
const auto resourceStartTime = std::chrono::system_clock::now(); | |
for(int i = 1 ; i < 101 ; i++){ | |
sprintf(str, "f%03d.png" , i); | |
readFromResource(str); | |
} | |
const auto resourceEndTime = std::chrono::system_clock::now(); | |
const auto resourceExecTime = resourceEndTime - resourceStartTime; | |
CCLOG("resourceExecTime : %lld ms" , std::chrono::duration_cast<std::chrono::milliseconds>(resourceExecTime).count()); | |
// zipから読み出す | |
const auto zipStartTime = std::chrono::system_clock::now(); | |
for(int i = 1 ; i < 101 ; i++){ | |
sprintf(str, "f%03d.png" , i); | |
readFromZip(str); | |
} | |
const auto zipEndTime = std::chrono::system_clock::now(); | |
const auto zipExecTime = zipEndTime - zipStartTime; | |
CCLOG("zipExecTime : %lld ms" , std::chrono::duration_cast<std::chrono::milliseconds>(zipExecTime).count()); | |
} | |
void HelloWorld::readFromResource(const char* _fileName){ | |
auto sprite = Sprite::create(_fileName); | |
this->addChild(sprite); | |
} | |
void HelloWorld::readFromZip(const char* _fileName){ | |
std::string fileName = "img_100/"; | |
fileName = fileName + _fileName; | |
// zip fileから指定した画像を読み出して表示 | |
unsigned long size = 0; | |
unsigned char* buf = FileUtils::getInstance()->getFileDataFromZip(path.c_str() , fileName.c_str(), (ssize_t*)&size); | |
auto img = new Image(); | |
img->initWithImageData(buf , size); | |
auto texture = new Texture2D(); | |
texture->initWithImage(img); | |
auto sprite = Sprite::createWithTexture(texture); | |
this->addChild(sprite); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cocos2d.h" | |
#import "network/HttpClient.h" | |
USING_NS_CC; | |
using namespace cocos2d::network; | |
class HelloWorld : public cocos2d::Layer | |
{ | |
public: | |
// there's no 'id' in cpp, so we recommend returning the class instance pointer | |
static cocos2d::Scene* createScene(); | |
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone | |
virtual bool init(); | |
// a selector callback | |
void menuCloseCallback(cocos2d::Ref* pSender); | |
// implement the "static create()" method manually | |
CREATE_FUNC(HelloWorld); | |
void httpCallBackResponse(HttpClient* client , HttpResponse* response); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment