i have a .png animation in my project with 700 pics and a size of 150 px x 150 px.
it works fine but everytime, the animation starts, the whole game freezes for about 0.1 sec. like its loading but i implemented the .png array in initWithSize. like this:
SKTextureAtlas *barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"];
NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNames];
NSArray *sortetBarrierUfoAtlasNames = [barrierUfoAtlasNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableArray *barrierUfoTextures = [NSMutableArray array];
for (NSString *filename in sortetBarrierUfoAtlasNames) {
SKTexture *texture = [barrierUfoAtlas textureNamed:filename];
[barrierUfoTextures addObject:texture];
}
self.barrierUfoAnimation = [SKAction animateWithTextures:barrierUfoTextures timePerFrame:0.024];
and then while playing after about 1-2 min. the animation is starting. it doesn´t need to load anything at this point, just start the animation. is there any way to improve it?
This is one of many ways to preload:
@implementation GameScene {
SKTextureAtlas *myAtlas1;
BOOL loadingComplete;
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
// the usual stuff...
loadingComplete = false;
[self loadMyAtlas1];
}
return self;
}
-(void)loadMyAtlas1 {
myAtlas1 = [SKTextureAtlas atlasNamed:@"MyAtlasName"];
[SKTextureAtlas preloadTextureAtlases:[NSArray arrayWithObject:myAtlas1] withCompletionHandler:^{
[self finishedLoading];
}];
}
-(void)finishedLoading {
// other stuff you might do here
loadingComplete = true;
}
-(void)update:(CFTimeInterval)currentTime {
if(loadingComplete) {
// run game code
} else {
// wait for the water to boil
}
}
来源:https://stackoverflow.com/questions/28056269/png-animation-slow-performance-in-spritekit