Cocos2d iphone CCFileUtils:从Cocos2D iphone 1.x中的类方法到Cocos2D 2.x中的实例方法的转换
您可能知道,CoCoS2D2 iphone 1.x中CCFileUtils的所有类方法都被重写为CoCoS2D2.x中singleton[CCFileUtils sharedFileUtils]的实例方法,因此Cocos2d iphone CCFileUtils:从Cocos2D iphone 1.x中的类方法到Cocos2D 2.x中的实例方法的转换,cocos2d-iphone,Cocos2d Iphone,您可能知道,CoCoS2D2 iphone 1.x中CCFileUtils的所有类方法都被重写为CoCoS2D2.x中singleton[CCFileUtils sharedFileUtils]的实例方法,因此 [CCFileUtils fullPathFromRelativePath:…解析类型:…] 我们需要使用 [[CCFileUtils SharedFileTils]相对路径的完整路径路径路径路径路径:maskFileName解析类型:&解析] 我已经为掩蔽精灵写了一个扩展(http:/
[CCFileUtils fullPathFromRelativePath:…解析类型:…]
我们需要使用
[[CCFileUtils SharedFileTils]相对路径的完整路径路径路径路径路径:maskFileName解析类型:&解析]
我已经为掩蔽精灵写了一个扩展(http://www.cocos2d-iphone.org/forum/topic/30494),它大量使用CCFileUtils,现在需要使其与cocos2d 1.x和2.x兼容
我知道CC_ENABLE_DEPRECATED标志有助于动态转换这些调用,但我希望有一个明确的解决方案。类似于类方法的东西,它将返回一个id供我使用,如下所示:
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]
}
当然,我在cocos1.x中得到了一个错误“没有选择器'sharedFileUtils'的已知实例方法”,因为没有这样的选择器。我应该如何重写它才能开始工作呢?好吧,我自己在睡了一会儿后就做了:) 共享代码:
/**In Cocos2d v 2.0 CCFileUtils class methods were moved to instance methods.
Here we set SSK_FILE_UTILS to class or instance depending on Cocos2D version.
*/
#ifdef COCOS2D_VERSION
#if COCOS2D_VERSION >= 0x00020000
#define SSK_FILE_UTILS [CCFileUtils sharedFileUtils]
#else
#define SSK_FILE_UTILS CCFileUtils
#endif
#else
#define SSK_FILE_UTILS nil
#endif
用法:
[SSK_FILE_UTILS fullPathFromRelativePath:... resolutionType:...]
嗯,我睡了一会儿后自己做的:) 共享代码:
/**In Cocos2d v 2.0 CCFileUtils class methods were moved to instance methods.
Here we set SSK_FILE_UTILS to class or instance depending on Cocos2D version.
*/
#ifdef COCOS2D_VERSION
#if COCOS2D_VERSION >= 0x00020000
#define SSK_FILE_UTILS [CCFileUtils sharedFileUtils]
#else
#define SSK_FILE_UTILS CCFileUtils
#endif
#else
#define SSK_FILE_UTILS nil
#endif
用法:
[SSK_FILE_UTILS fullPathFromRelativePath:... resolutionType:...]