Hi guys, is there any way to check if a file exists before loading? I’ve seen you can call CCFileUtils::getFileData and it will return NULL if the file doesn’t exist, but this will also load the full file if it does exist.
This is fine for methods like CCSprite::spriteWithFile that need to load the data if the file exists. However I simply want to check if a file exists and return a filename if it does or an alternate filename if it doesn’t. Kind of how iOS’s @2x file naming for assets works.
If there is a way to do this please advise. I know how to do it for iOS and Android, but my game has to support other platforms as well which is why I chose cocos2d-x
Otherwise if I could humbly make a suggestion for a future release…
no need to add this feature.
using this code would meet your need.
>
[…]
For other people reading this, unfortunately you can’t use this solution on Android (it works fine on other platforms). On Android the resources are packed into a .zip file, so you can’t just grab a normal file handle. Using a combination of these two methods is the best way to ensure platform compatibility.
Ren Wang wrote:
> no need to add this feature.
> using this code would meet your need.
>
> […]
>
For other people reading this, unfortunately you can’t use this solution on Android (it works fine on other platforms). On Android the resources are packed into a .zip file, so you can’t just grab a normal file handle. Using a combination of these two methods is the best way to ensure platform compatibility.
>
Ben
oh. sorry . i just have tried it on android . as you said , did not work on android~ ,thank you for pointing out .