CCTexture2Dでテクスチャを作成して、CCSpriteで表示する。
例えばこんな感じ。
CCSprite* createSpriteWithRawData(const void* data, unsigned int width, unsigned int height)
{
CCTexture2D* texture = new CCTexture2D();
if (texture && texture->initWithData(data, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSizeMake(width, height))) {
texture->autorelease();
return CCSprite::createWithTexture(texture);
}
CC_SAFE_DELETE(texture);
return NULL;
}
※ CCTexture2D::initWithDataは、dataをglTexture2Dに渡してグラフィックスハードウェアに転送している。従ってdataをメモリ上に確保しておく必要はない。
CCImageで画像フォーマットを解析してから、CCTexture2DとCCSpriteで表示する。
例えばこんな感じ。
CCSprite* createSpriteWithPngData(void* data, unsigned long data_length)
{
CCImage* image = new CCImage();
if (image && image->initWithImageData(data, data_length, CCImage::kFmtPng)) {
image->autorelease();
CCTexture2D* texture = new CCTexture2D();
if (texture && texture->initWithImage(image)) {
texture->autorelease();
return CCSprite::createWithTexture(texture);
}
CC_SAFE_DELETE(texture);
return NULL;
}
CC_SAFE_DELETE(image);
return NULL;
}
※ CCImage::initWithImageDataは、dataを必要に応じてコピーしている。従ってdataをメモリ上に確保しておく必要はない。

