-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSafeSprite.cpp
34 lines (25 loc) · 920 Bytes
/
SafeSprite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/****************************************************************************
SafeSprite.cpp
When there is no image file available, shows a predetermined image instead crashing
Created by Daniel Alias on 2024/08/07 (yyyy/mm/dd) under MIT Licence
****************************************************************************/
#include "SafeSprite.h"
USING_NS_AX;
SafeSprite* SafeSprite::create(const std::string& filename) {
auto finalFilename = filename;
auto fileExist = FileUtils::getInstance()->isFileExist(finalFilename);
if (!fileExist) {
finalFilename = "HelloWorld.png";
#ifndef NDEBUG
AXLOG("File %s not found",filename.c_str());
#endif
}
SafeSprite* sprite = new SafeSprite();
if (sprite && sprite->initWithFile(finalFilename)) {
sprite->autorelease();
return sprite;
} else {
AX_SAFE_DELETE(sprite);
return nullptr;
}
}