ios - 更改游戏纹理但图像未根据cocos hd definition替换

标签 ios cocos2d-iphone textures

我正在用 cocos2d 制作游戏。我正在检查 Sprite 的级别并相应地更新纹理。 现在开始时图像是高清的。现在当游戏开始并且我开始移动 Sprite 时,高清图像被普通图像取代。我正在检查用这段代码替换纹理。

int value = [self.weapon.weaponLevel intValue];
NSString *path = [[NSBundle mainBundle]pathForResource:@"name" ofType:@"png"];
UIImage *imageView = [[UIImage alloc]initWithContentsOfFile:path];
CCTexture2D *frame = [[CCTexture2D alloc]initWithImage:imageView];
[self.player setTexture:frame];

谁能帮帮我。谢谢。 问候。

最佳答案

当您可以使用在内部处理所有路径解析和 HD/SD 检测的 CCTextureCache 时,无需通过 NSBundleUIImage .

此外,顾名思义,它会缓存纹理,以便后续使用相同的 Sprite 文件会更快:

这是你需要的:

CCTexture2D *frame = [[CCTextureCache sharedTextureCache] addImage:@"name.png"];
[self.player setTexture:frame];

关于ios - 更改游戏纹理但图像未根据cocos hd definition替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9407936/

相关文章:

c++ - 在 iOS 和 Mac OS X 应用程序中使用 C++

IOS - 使用自动布局和 drawRect

iphone - 无法在 applicationWillResignActive 中获取当前 ViewController

ios - Cocos2D - 使 Sprite 平滑地跟随和旋转触摸

c - Cuda 中的纹理坐标

ios - 如何在 iOS 9 中使用共享扩展共享笔记数据?

iphone - 横向模式下 Cocos 2d 和 CGPoint 混淆

iphone - 第二次加载场景时不会调用执行选择器

c++ - 如何从 OpenGL 4.5 中的单个立方体贴图纹理创建立方体贴图阵列纹理?

opengl - 无法从附加到 FBO 的深度纹理读取深度值