スプライト (30x30) でいっぱいのフィールドがあります。
スプライトを作成する前に、次のコードでテクスチャ アトラスをプリロードしています。
- (void)preloadAllAtlases
{
BGLog();
_tilesAtlas = [SKTextureAtlas atlasNamed:@"Tiles"];
_tilesTextures = [NSMutableDictionary new];
__weak typeof (shared) weakSelf = self;
[SKTextureAtlas preloadTextureAtlases:@[_tilesAtlas]
withCompletionHandler:^
{
for (NSString *textureFullName in weakSelf.tilesAtlas.textureNames) {
NSString *textureName = [textureFullName componentsSeparatedByString:@"@"][0];
weakSelf.tilesTextures[textureName] = [SKTexture textureWithImageNamed:textureName];
}
}];
}
このメソッドは、appicationDidFinishLaunchingWithOptions でシングルトンから 1 回呼び出されます。
時間が来たら、SKTextures から SKSpriteNodes を生成し、複合ノード (すべての SKSpriteNodes を含むノード) を SKScene に追加します。しかし... 192 個のスプライトを表示/レンダリングするのに 1 ~ 1.5 秒かかります。「時間プロファイラー」を使用すると、[SKSpriteNode spriteNodeWithTexture:] にかなりの時間がかかることがわかりました。
スクリーンショット:
スプライトの作成を高速化する方法はありますか?
どうも。