我的项目中有一个 .png 动画,包含 700 张图片,尺寸为 150 像素 x 150 像素。
它工作正常,但每次动画开始时,整个游戏都会冻结约 0.1 秒。喜欢它的加载,但我在 initWithSize 中实现了 .png 数组。像这样:
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];
然后在玩大约 1-2 分钟后。动画正在开始。
此时不需要加载任何内容,只需启动动画即可。
有什么办法可以改善吗?
This is 多种方法之一预加载:
@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
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)