【发布时间】: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