我正在尝试在游戏开始之前预加载我正在使用的图像。
但是,当我环顾四周时,我发现了这一行,它是在cocos2d v2中写的。
[[CCTextureCache sharedTextureCache ] addImage:@"objects.png" ];如何在cocos2d v3中预加载图像?
发布于 2014-04-03 19:00:16
在cocos2d-v3中,您可以简单地使用CCTexture(以前的CCTexture2D)的textureWithFile: initializer,而不是使用初始化器。
您的代码将如下所示:
CCTexture* texture = [CCTexture textureWithFile:@"objects.png"];如果我对文档的理解正确,它将缓存纹理文件(参见CCTexture extureWithFile:)。因此,如果您之前已经加载了纹理,它将在缓存中,并且先前创建的纹理将由上面的代码返回。
这里还有另一个“变通办法”的解决方案:https://gamedev.stackexchange.com/questions/72713/preload-in-cocos2d-v3
发布于 2014-10-26 12:06:54
实际上,在Cocos2D版本3.x中,CCTextureCache仍然存在。但如果您只导入"cocos2d.h“,则无法直接访问它。要访问它,您必须导入"CCTextureCache.h“。
尝试以下代码:
#import "CCTextureCache.h"
- (void) preloadImages
{
[[CCTextureCache sharedTextureCache] addImage:@"image1.png"];
[[CCTextureCache sharedTextureCache] addImage:@"image2.png"];
[[CCTextureCache sharedTextureCache] addImage:@"image3.png"];
[[CCTextureCache sharedTextureCache] addImage:@"image4.png"];
[[CCTextureCache sharedTextureCache] addImage:@"image5.png"];
}发布于 2014-11-05 02:47:09
试试这个:
cocos2d::Director::getInstance()->getTextureCache()->addImage("objects.png");https://stackoverflow.com/questions/22751186
复制相似问题