| 318 | } |
| 319 | |
| 320 | bool Sprite::initWithImageData(const Data& imageData, std::string_view key) |
| 321 | { |
| 322 | if (imageData.isNull() || key.empty()) |
| 323 | { |
| 324 | AXLOGD("Call Sprite::initWithImageData empty data or blank key."); |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | //_fileName = filename; |
| 329 | |
| 330 | Texture2D *texture = _director->getTextureCache()->addImage(imageData, key); |
| 331 | |
| 332 | if (texture) |
| 333 | { |
| 334 | Rect rect = Rect::ZERO; |
| 335 | rect.size = texture->getContentSize(); |
| 336 | return initWithTexture(texture, rect); |
| 337 | } |
| 338 | |
| 339 | // don't release here. |
| 340 | // when load texture failed, it's better to get a "transparent" sprite then a crashed program |
| 341 | // this->release(); |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | Sprite::Sprite() |
| 346 | { |