Spritekit - 动画&内存管理

时间:2013-11-11 16:36:54

标签: ios memory-management sprite-kit

我目前正在使用iOS上的Sprite Kit来弄清楚它是否适合制作相对简单的2D游戏。

由于我的ActionScript背景,我非常适合使用Sprite Kit代码

但有些事情我无法弄明白。使用Texture Atlas作为资源的动画节点非常重要。我已经在我的项目中导入了一个图集(纹理大小约为35MB)。将纹理预加载到RAM似乎没问题但是目前我运行实际的动画,堆大小指数(从大约80MB到780MB)

这是我的代码:

self.noahFrames = [[NSMutableArray alloc] init];
SKTextureAtlas *noahAtlas = [SKTextureAtlas atlasNamed:@"noahAnimati"];

int imgCount = noahAtlas.textureNames.count;
for (int i=1; i <= imgCount; i++) {
    NSString *textureName = [NSString stringWithFormat:@"NoahMainMenuAnimation_%d", i];
    SKTexture *temp = [noahAtlas textureNamed:textureName];
    [self.noahFrames addObject:temp];
}


SKSpriteNode *noahNode = [self createSpriteWithName:@"noah" imagePath:@"Noah_main_menu_hd" positionXPath:@"MainMenu.Noah.x" positionYPath:@"MainMenu.Noah.y" scalePath:@"MainMenu.Noah.scale"];
[self addChild:noahNode];

//up to this point everything goes fine

[noahNode runAction:[SKAction repeatActionForever:
                     [SKAction animateWithTextures:self.noahFrames
                                      timePerFrame:0.1f
                                            resize:YES
                                           restore:YES]] withKey:@"animatedNoah"];

所以我想我的实际问题是为什么应用程序在调用SKAction动画后会变得非常疯狂?我一定错过了一些相当明显的东西......

1 个答案:

答案 0 :(得分:0)

我知道当一个纹理加载到图形内存中时,它的加载没有任何压缩,但我不认为xcode监视图形内存,所以这对我来说真的很奇怪。 我通常像你一样加载和执行动画,我没有这样的记忆行为,但是我在模拟器上测试时注意到它。您是否在测试中使用iOS模拟器?当您达到这些内存级别时,您的应用程序是否会崩溃?