Hi all and thanks in advance for your help.
I’m using cocos2dx 3.2 and I’m trying to load remote PNG images and save them to file, for later use. These images have alpha, but when I display them on screen, transparent areas are black.
Here’s my code, I’m using HTTPRequest for remote loading.
HttpRequest* request = new HttpRequest();
request->setUrl(url.c_str());
request->setRequestType(HttpRequest::Type::GET);
request->setResponseCallback(CC_CALLBACK_2(RemoteSprite::onImageDownloaded, sprite));
request->setTag(name.c_str());
HttpClient::getInstance()->sendImmediate(request);
request->release();
void RemoteSprite::onImageDownloaded(HttpClient* client, HttpResponse* res) {
std::vector<char> *buffer = response->getResponseData();
Image * img = new Image();
img->initWithImageData( reinterpret_cast<unsigned char *> (&(buffer->front())), buffer->size());
std::string writablePath = FileUtils::getInstance()->getWritablePath();
writablePath.append(response->getHttpRequest()->getTag());
img->saveToFile(writablePath.c_str());
this->setTexture(writablePath.c_str());
}
Do you have any idea? What am I doing wrong?
Thank you
Bye