2

I'm currently messing around with Sprite Kit on iOS to figure out if it would be a fitting framework to make relatively simple 2D game in.

Due to my ActionScript background, i am very comfortable working with Sprite Kit code-wise

But there is something i just can't figure out. Animated nodes with Texture Atlas as a resource are incredibly memory heavy. I've imported an atlas into my project (size of textures is about 35MB). Preloading textures into RAM seems ok but at the moment i run the actual animation, the heap size increases exponentinaly (from about 80MB to 780MB)

Here goes my code:

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"];

So i guess my actual question is why does the application become that insanely memory heavy after calling the SKAction animation ? I must be missing something rather obvious ...

Casper522
  • 95
  • 1
  • 12
  • So the moment you single-step over the runAction line the memory usage increases? Or are you perhaps running this action over and over again every frame, possibly for multiple nodes? – CodeSmile Nov 11 '13 at 18:51
  • Exactly. And no, i dont call the action over and over. Its called just once and for one node. – Casper522 Nov 11 '13 at 19:33
  • 1
    I am running into the same issue with iPad 2. My spritekit based app released on the app store today crashes instantly when the view controller with spritekit views are to be displayed. These spritekit views have NO animation, just simple single color spritenodes (not even any images, just simple single color nodes). I do have 7 spritekit views on the same page, but the iPad 2 can't handle it. – Shawn Dec 19 '13 at 20:53
  • Another approach to reducing texture memory can be found at this answer http://stackoverflow.com/a/38679128/763355 – MoDJ Aug 02 '16 at 09:21

1 Answers1

0

I do know that when a texture is loaded in graphic memory it's loaded without any compression, but I don't think that xcode monitors graphic memory, so it's really strange to me. I usually load and execute animations just like you do and I don't have such memory behaviour, but i noticed it when testing on the simulator. Are you using iOS simulator for your tests? Does your application crash when you reach those memory levels?

membersheep
  • 504
  • 4
  • 12
  • That is a good point you've got there. Application does not crash after reaching those memory levels. I'm currently not in a possession of an iOS device but i will send it to friend of mine so he can try it on his iPad and see whats what. I'm gonna let you know how it went. – Casper522 Nov 12 '13 at 18:44
  • So i tried to run the application on device (iPad2). few frames after starting the animation heap size hit 256MB (which is the most system gives you on iPad 2... i guess) and crashed. – Casper522 Nov 12 '13 at 21:51
  • Maybe your code is called multiple times (try to debug with a nslog) or the error is in another part of your program. – membersheep Nov 13 '13 at 17:16