gpt4 book ai didi

image - TextureMgr 怎么了?

转载 作者:行者123 更新时间:2023-12-04 06:37:32 25 4
gpt4 key购买 nike

在 cocos2d 中,曾经有一个 TextureMgr 方法(异步),可以让您加载图像以供以后使用。现在当我使用 TextureMgr 时,它说它是未声明的。它被弃用了吗?我在 .99.5 上。如果它不再可用,用什么代替它?有什么可以做与这条线相同的事情吗?

 [[TextureMgr sharedTextureMgr] addImageAsync:...NSString goes here... target:self selector:@selector(method:)];

最佳答案

看看 CCTextureCache

http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_texture_cache.html

也许它是你正在寻找的。

当您创建任何带有纹理的对象时会使用此缓存:例如 sprite。您可以使用它来预缓存您的图像。

编辑:
CCTextureCache 用于创建带有纹理的 ang 对象,正如我所说 - 因此,如果纹理已经在缓存中,那么如果您先加载纹理然后创建对象,则元素创建要快得多。

例如,如果您正在编写这样的代码:
id sprite = [CCSprite spriteWithFile: @"my-file.png"]
并且 @"my-file.png"纹理不在缓存中,它将首先加载并且需要一些时间(比创建对象要多得多)。

如果您正在编写这样的代码:

id sprite1 = [CCSprite spriteWithFile: @"my-file.png"];
id sprite2 = [CCSprite spriteWithFile: @"my-file.png"];

然后 sprite1 的创建速度会很慢, sprite2 的创建速度会快很多,因为纹理已经在缓存中了。

您可以手动将纹理添加到缓存
[[CCTextureCache sharedTextureCache] addImage: @"my-file.png"];
并且使用此纹理创建所有对象将很快。

当您必须预缓存纹理时,代码中的常见位置是游戏加载或关卡包加载或关卡加载。

还有如果您需要使用 SimpleAudioEngine 单例,您可以预缓存声音

关于image - TextureMgr 怎么了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686707/

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