0

I am trying to do some animations using SpriteKit and atlas files generated from texture packer, but when I start the scene, Animations are very low in fps(1-5 fps) at first 10 secs and CPU usage is about 90-100%. After that it goes fine, any ideas on how to resolve the same. Memory Usage is about 55 MB.

self.atlas = [SKTextureAtlas atlasNamed:BABY_STABLE_ATLAS_NAME];
self.atlas2=[SKTextureAtlas atlasNamed:BABYCAP_ATLAS_NAME];
sprite=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_BODY_0000 ];
sprite2=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_BABYCLOTHRED_0000 ];
sprite3=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_TSHIRTSRED_0000 ];
sprite4=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_LEGR_0000 ];
sprite5=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_FOOTR_0000 ];
sprite6=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_LEGL_0000 ];
sprite7=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_FOOTL_0000 ];
sprite8=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_HANDL_0000 ];
sprite9=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_HANDR_0000 ];
sprite10=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EARR_0000 ];
sprite11=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EARL_0000 ];
sprite12=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_FACE_0000 ];
sprite13=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_NOSE_0000 ];
sprite14=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_MOUTH_0000 ];
sprite15=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EYER_0000 ];
sprite16=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EYEL_0000 ];
sprite17=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EYEBROWL_0000 ];
sprite18=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_EYEBROWR_0000 ];
sprite19=[SKSpriteNode spriteNodeWithTexture:BABY_STABLE_TEX_BABY_STABLE_HAIR_0000 ];


sprite.anchorPoint = CGPointMake(0.0,0.0);
sprite2.anchorPoint = CGPointMake(0.0,0.0);
sprite3.anchorPoint = CGPointMake(0.0,0.0);
sprite4.anchorPoint = CGPointMake(0.0,0.0);
sprite5.anchorPoint = CGPointMake(0.0,0.0);
sprite6.anchorPoint = CGPointMake(0.0,0.0);
sprite7.anchorPoint = CGPointMake(0.0,0.0);
sprite8.anchorPoint = CGPointMake(0.0,0.0);
sprite9.anchorPoint = CGPointMake(0.0,0.0);
sprite10.anchorPoint = CGPointMake(0.0,0.0);
sprite11.anchorPoint = CGPointMake(0.0,0.0);
sprite12.anchorPoint = CGPointMake(0.0,0.0);
sprite13.anchorPoint = CGPointMake(0.0,0.0);
sprite14.anchorPoint = CGPointMake(0.0,0.0);
sprite15.anchorPoint = CGPointMake(0.0,0.0);
sprite16.anchorPoint = CGPointMake(0.0,0.0);
sprite17.anchorPoint = CGPointMake(0.0,0.0);
sprite18.anchorPoint = CGPointMake(0.0,0.0);
sprite19.anchorPoint = CGPointMake(0.0,0.0);


sprite.position = CGPointMake(0,0);
sprite2.position = CGPointMake(0,0);
sprite3.position = CGPointMake(0,0);
sprite4.position = CGPointMake(0,0);
sprite5.position = CGPointMake(0,0);
sprite6.position = CGPointMake(0,0);
sprite7.position = CGPointMake(0,0);
sprite8.position = CGPointMake(0,0);
sprite9.position = CGPointMake(0,0);
sprite10.position = CGPointMake(0,0);
sprite11.position = CGPointMake(0,0);
sprite12.position = CGPointMake(0,0);
sprite13.position = CGPointMake(0,0);
sprite14.position = CGPointMake(0,0);
sprite15.position = CGPointMake(0,0);
sprite16.position = CGPointMake(0,0);
sprite17.position = CGPointMake(0,0);
sprite18.position = CGPointMake(0,0);
sprite19.position = CGPointMake(0,0);

[sprite setHidden: NO];
[sprite2 setHidden: NO];
[sprite3 setHidden: NO];
[sprite4 setHidden: NO];
[sprite5 setHidden: NO];
[sprite6 setHidden: NO];
[sprite7 setHidden: NO];
[sprite8 setHidden: NO];
[sprite9 setHidden: NO];
[sprite10 setHidden: NO];
[sprite11 setHidden: NO];
[sprite12 setHidden: NO];
[sprite13 setHidden: NO];
[sprite14 setHidden: NO];
[sprite15 setHidden: NO];
[sprite16 setHidden: NO];
[sprite17 setHidden: NO];
[sprite18 setHidden: NO];
[sprite19 setHidden: NO];



[self  addChild:sprite];
[self  addChild:sprite2];
[self  addChild:sprite3];
[self  addChild:sprite4];
[self  addChild:sprite5];
[self  addChild:sprite6];
[self  addChild:sprite7];
[self  addChild:sprite8];
[self  addChild:sprite9];
[self  addChild:sprite10];
[self  addChild:sprite11];
[self  addChild:sprite12];
[self  addChild:sprite13];
[self  addChild:sprite14];
[self  addChild:sprite15];
[self  addChild:sprite16];
[self  addChild:sprite17];
[self  addChild:sprite18];
[self  addChild:sprite19];


spriteAction=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_BODY timePerFrame:0.05]];
spriteAction2=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_BABYCLOTHRED timePerFrame:0.05]];
spriteAction3=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_TSHIRTSRED timePerFrame:0.05]];
spriteAction4=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_LEGR timePerFrame:0.05]];
spriteAction5=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_FOOTR timePerFrame:0.05]];
spriteAction6=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_LEGL timePerFrame:0.05]];
spriteAction7=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_FOOTL timePerFrame:0.05]];
spriteAction8=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_HANDL timePerFrame:0.05]];
spriteAction9=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_HANDR timePerFrame:0.05]];
spriteAction10=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EARR timePerFrame:0.05]];
spriteAction11=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EARL timePerFrame:0.05]];
spriteAction12=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_FACE timePerFrame:0.05]];
spriteAction13=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_NOSE timePerFrame:0.05]];
spriteAction14=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_MOUTH timePerFrame:0.05]];
spriteAction15=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EYER timePerFrame:0.05]];
spriteAction16=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EYEL timePerFrame:0.05]];
spriteAction17=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EYEBROWL timePerFrame:0.05]];
spriteAction18=[SKAction repeatActionForever:[SKAction animateWithTextures:BABY_STABLE_ANIM_BABY_STABLE_EYEBROWR timePerFrame:0.05]];


[sprite runAction:spriteAction];
[sprite2 runAction:spriteAction2];
[sprite3 runAction:spriteAction3];
[sprite4 runAction:spriteAction4];
[sprite5 runAction:spriteAction5];
[sprite6 runAction:spriteAction6];
[sprite7 runAction:spriteAction7];
[sprite8 runAction:spriteAction8];
[sprite9 runAction:spriteAction9];
[sprite10 runAction:spriteAction10];
[sprite11 runAction:spriteAction11];
[sprite12 runAction:spriteAction12];
[sprite13 runAction:spriteAction13];
[sprite14 runAction:spriteAction14];
[sprite15 runAction:spriteAction15];
[sprite16 runAction:spriteAction16];
[sprite17 runAction:spriteAction17];
[sprite18 runAction:spriteAction18];
Simulator
  • 156
  • 1
  • 11

1 Answers1

0
-(void)preloadTexture
{

    //where first and second your texture atlas
    NSArray *textureArray=@[@"first",@"second"];
    [SKTextureAtlas preloadTextureAtlases:textureArray withCompletionHandler:^{
        //all texture atlas are loaded in memory now you can save
        [self initAnimation];
    }];
}

-(void)initAnimation
{
    //save fetch and intailize your sprites

}
dragoneye
  • 703
  • 6
  • 14
  • thanks for that, I tried it but still getting the initial CPU Peak and FPS Lag – Simulator Jul 29 '15 at 09:54
  • what is the size of your texture atlas – dragoneye Jul 29 '15 at 09:57
  • please download it from here [Download](https://www.zipshare.com/download/eyJhcmNoaXZlSWQiOiJhYTE0OWIyMC1jYjg1LTQ0MGQtODZiMS1jMmRkYWM2MDVlYjgiLCJlbWFpbCI6Im5vLmlkLmZvci5tLnVrdWxAZ21haWwuY29tIn0=) – Simulator Jul 29 '15 at 10:09
  • i seen your code where you checking your game on device or simulator – dragoneye Jul 29 '15 at 10:21
  • device, iPad air and iPad 4th gen retina – Simulator Jul 29 '15 at 10:22
  • i seen your code where you checking your game on device or simulator check it on device not simulator and secondly create a sprite sheet class which would save your all animation as a NSDictionary and play them with a keyname u defined all your animation only once thats bad idea . – dragoneye Jul 29 '15 at 10:26
  • I am checking it on device only, once again if you could help with that, it would be really helpful, as I am just a beginner here. – Simulator Jul 29 '15 at 10:28
  • @Simulator what are your nodes count and draws count (you can enable debugging labels in view controller)? What are the iOS versions on your testing devices? – Whirlwind Jul 29 '15 at 11:23
  • As written in the code, there are about 19 SKSpriteNodes, I don't have idea about draw counts, My testing devices are on 8.3(iPad 4th Gen) and 8.4(iPad Air) – Simulator Jul 29 '15 at 11:27
  • @Simulator You can enable/disable debugging information inside view controller class. This can be useful while development phase. There are information like nodes count, draws count, visual physics representation... Read more here : https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKView/index.html#//apple_ref/occ/instp/SKView/showsDrawCount – Whirlwind Jul 29 '15 at 12:55
  • Thanks for that, it is 19 nodes and 1 draw count. – Simulator Jul 30 '15 at 03:54