As you probably know, all class methods of CCFileUtils in Cocos2D-iphone 1.x were rewritten as instance methods of the singleton [CCFileUtils sharedFileUtils] in Cocos2d 2.x, so instead of
[CCFileUtils fullPathFromRelativePath:... resolutionType:...]
we need to use
[[CCFileUtils sharedFileUtils] fullPathFromRelativePath:maskFileName resolutionType:&resolution]
I’ve written an extension for masking sprites (http://www.cocos2d-iphone.org/forum/topic/30494), which uses CCFileUtils heavily and now need to make it compatible with both cocos2d 1.x and 2.x
I know about CC_ENABLE_DEPRECATED flag which helps to translate those calls on the fly, but i’d like to have a clear solution. Something like a class method which will return me an id for use it like this:
Method:
+ (id) getCCFileUtils
{
id fileUtils = [CCFileUtils class];
if ([fileUtils instancesRespondToSelector:@selector(fullPathFromRelativePath:resolutionType:)])
{
return [fileUtils sharedFileUtils];
}
else
{
return fileUtils;
}
}
Usage:
id myFileUtils = [MyClass getCCFileUtils];
[myFileUtils fullPathFromRelativePath:maskFileName resolutionType:&resolution]
}
For sure, I get an error “No known instance method for selector ‘sharedFileUtils'” in Cocos 1.x, because there is no such selector. How should i rewrite it to get working?
Well, i did it myself after sleeping a bit 🙂
Share the code:
Usage: