iphone - Cocos2D iPhone - 这会节省内存吗?

标签 iphone ios cocos2d-iphone

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

类似于:

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

我的问题是:假设我想要多个使用相同纹理的 Sprite ,而我这样做了

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 倍的内存吗? (或者换句话说,纹理会被复制到每个代理,还是 Sprite 只是一个引用原始纹理的“空盒子”?

如果后者是答案,那么类似 Sprite 的内存使用量不会那么大,对吧?

谢谢。

最佳答案

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

关于iphone - Cocos2D iPhone - 这会节省内存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9170601/

相关文章:

ios - Google Places API 未返回响应

ios - 为什么我无法从父级 CCLayer 重置我的 CCParticleSystemQuad?

iphone - Cocos2D游戏教程/游戏建议

ios - 可以在单独的线程中使用 NSFetchedResultsController 来加载 TableViewCells 吗?

iphone - 如何使用 MPMoviePlayerController 从视频文件中获取每秒实时帧数而不观看视频?

ios - 通过 UITableView 编辑 NSManagedObjects 的现有解决方案?

ios - Cocos2d .isTouchEnabled 不调用单点触摸方法

iphone - 缓存数据的最佳实践是什么?

iphone - PDF 查看器 iPad 应用程序

ios - LineChart 绘图数据未填充其 UIView