【问题标题】:High memory usage in SpriteKit when using texture atlas使用纹理图集时 SpriteKit 中的高内存使用率
【发布时间】:2013-12-04 14:23:59
【问题描述】:

我有 100 个纹理,每个大小约为 100 kb,我想创建一个 SKAction,以 25fps 的速度对这些纹理进行 4 秒的动画处理,并永远循环该动作。我正在从一个地图集(或多个,因为 Xcode 警告我它将地图集分成 9 个)加载它们。

问题是当我运行该操作时,内存使用量从 4 mb 增加到 150 mb。前三个步骤一切正常。资产的总大小约为 12 mb。

多图集的使用(Xcode 在编译时拆分它们)会导致这个问题吗?

// Load the frames to an array
NSArray *sTreesRightAnimationFrames = ITBLoadFramesFromAtlas(@"s01-trees-right", @"s01-trees-right-", 100);
// Create the action
SKAction *sTreesRightAction = [SKAction animateWithTextures:sTreesRightAnimationFrames timePerFrame:1.0f / 25.0f];
// Create the forever action
SKAction *sTreesRightForeverAction = [SKAction repeatActionForever:sTreesRightAction];

// Preload the textures and run the action
[SKTexture preloadTextures:sTreesLeftAnimationFrames withCompletionHandler:^{
    [treesLeft runAction:sTreesLeftForeverAction];
}];

【问题讨论】:

  • 对于非常大的纹理,将它们放在图集中与每帧的 PNG 图像没有任何区别。你可以做的是减少纹理的内存大小stackoverflow.com/a/38679128/763355

标签: objective-c sprite-kit


【解决方案1】:

大小是文件大小,我猜?因为它们不会告诉您给定图像的纹理将使用多少内存。要计算任何给定(图集)图像的值,请使用:

width x height x (color bit depth / 8) = size in bytes

例如:

1024 x 1024 x (32 / 8) = 4194304 Bytes = 4 Megabytes

【讨论】:

  • 是的,它们是文件大小。在这种情况下,一切都会检查。在这种情况下,我需要找到一种更好的方法来为这些纹理设置动画。
猜你喜欢
  • 2021-05-21
  • 2013-04-24
  • 2018-03-22
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
  • 2014-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多