【问题标题】:Cocos2D iPhone - will this save memory?Cocos2D iPhone - 这会节省内存吗?
【发布时间】:2012-02-07 03:26:40
【问题描述】:

当您使用纹理在 cocos 上创建精灵时,您会分配内存。

类似:

CCTexture2D *textureProxy = [[CCTexture2D alloc] initWithImage:image];
CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy];

我的问题是:假设我想要几个使用相同纹理的精灵,我会这样做

CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy];
CCSprite *proxy2 = [CCSprite spriteWithTexture:textureProxy];
CCSprite *proxy3 = [CCSprite spriteWithTexture:textureProxy];
CCSprite *proxy4 = [CCSprite spriteWithTexture:textureProxy];
CCSprite *proxy5 = [CCSprite spriteWithTexture:textureProxy];

我会使用 5 倍以上的内存吗? (或者换句话说,纹理会被复制到每个代理,还是精灵只是一个引用原始纹理的“空盒子”?

如果后者是答案,那么类似精灵的内存使用量并没有那么大,对吧?

谢谢。

【问题讨论】:

    标签: iphone ios cocos2d-iphone


    【解决方案1】:

    Sprite 仅保留对 textureProxy 的引用。即使您使用spriteWithFile: 创建每个精灵,文件名也会缓存在CCTextureCache 中。

    【讨论】:

      【解决方案2】:

      在 cocos 中为纹理和变量分配了不同的内存。因此,如果您继续使用相同的纹理创建变量,则不会多次添加纹理内存。 CCSprite 对象是自动释放的对象。

      【讨论】:

      • 感谢您的信息。我担心我使用了太多的内存。 :D
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-05
      • 2011-11-02
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      相关资源
      最近更新 更多