gpt4 book ai didi

ios - 我应该用什么替换 CCTexture2D initWithImage?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:52 25 4
gpt4 key购买 nike

我应该用什么替换 CCTexture2D initWithImage?

我有这个方法:

CCTexture2D *noMutableTexture = [[[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]] autorelease];

我跳转到定义,发现现在唯一的方法是:

- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size

- (id) initWithCGImage:(CGImageRef)cgImage resolutionType:(ccResolutionType)resolution

我猜是后者,但我不确定如何构建 CGImageRef,也不知道 ccResolutionType 是什么。

任何帮助将不胜感激。谢谢

最佳答案

//! ccResolutionType
typedef enum
{
//! Unknonw resolution type
kCCResolutionUnknown,
#ifdef __CC_PLATFORM_IOS
//! iPhone resolution type
kCCResolutioniPhone,
//! RetinaDisplay resolution type
kCCResolutioniPhoneRetinaDisplay,
//! iphone5 resolution type
kCCResolutioniPhone5Display,
//! iPad resolution type
kCCResolutioniPad,
//! iPad Retina Display resolution type
kCCResolutioniPadRetinaDisplay,

#elif defined(__CC_PLATFORM_MAC)
//! Mac resolution type
kCCResolutionMac,

//! Mac RetinaDisplay resolution type (???)
kCCResolutionMacRetinaDisplay,
#endif // platform

} ccResolutionType;

resolutionType 的可能值。

因此基于设备类型,iPhone 或 iPhone retina(3.5/4 英寸)、iPad、iPad retina。分辨率类型的值各不相同。

- (id) initWithCGImage:(CGImageRef)cgImage resolutionType:(ccResolutionType)resolution

你可以像这样构建一个 CGImageRef :

UIImage *someImage = [UIImage imageNamed:@"someImage.png"];
CGImageRef someImageRef = someImage.CGImage;

你可以这样检查你的设备类型

-(ccResolutionType)resolutionType{
static NSInteger ret=-1;

if (ret != -1) return ret;

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if( CC_CONTENT_SCALE_FACTOR() == 2 )
ret = kCCResolutioniPadRetinaDisplay;
else
ret = kCCResolutioniPad;
}
else
{
if( CC_CONTENT_SCALE_FACTOR() == 2 ){
BOOL isWideScreenEnabled = (BOOL)(fabs((double)[UIScreen mainScreen].bounds.size.height -
(double)568) < DBL_EPSILON);

if (isWideScreenEnabled) {
ret = kCCResolutioniPhone5Display;
}
else ret = kCCResolutioniPhoneRetinaDisplay;
}
else
ret = kCCResolutioniPhone;
}

if(ret == -1)
ret = kCCResolutionUnknown;


return ret;
}

所以,总的来说,如果你想从 UIImage 创建一个 CCTexture,那么

UIImage *someImage = [UIImage imageNamed:@"someImage.png"];
CGImageRef someImageRef = someImage.CGImage;
CCTexture2D *tex = [[CCTexture2D alloc] initWithCGImage:someImageRef resolutionType:kCCResolutionUnknown ];

CCTexture2D *tex = [[CCTexture2D alloc] initWithCGImage:someImageRef resolutionType:[self resolutionType]];

关于ios - 我应该用什么替换 CCTexture2D initWithImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17130058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com