我正在尝试使用从纹理打包器生成的SpriteKit和atlas文件来制作一些动画,但是当我启动场景时,动画在前10秒内的fps(1-5 fps)非常低,CPU使用率约为90- 100%。在那之后它很好,任何关于如何解决相同的想法。内存使用量约为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];
答案 0 :(得分: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
}