Texture Atlas について見ていきます。
Xcodeでは、テクスチャが複数に分かれている場合でも、自動的に1枚のテクスチャとして扱えるようにしてくれます。
Texture Atlas を使うことでパフォーマンスも向上するようです。
まず、複数のテクスチャを同じフォルダに入れ、フォルダ名を xxx.atlas のように変更します。
フォルダをプロジェクトに追加します。
PROJECT の Build Settings に SpriteKit Deployment Options が現れるので、
Enable Texture Atlas Generation を Yes にします。
TARGETS の Build Phases で Copy Bundle Resources を見ると、koma.atlas が追加されているのが分かります。
SKTextureAtlas を使ってテクスチャを読み込んでいきます。
HelloScene.m
- (void)createSceneContents
{
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"koma"];
for (int i=0; i < 8; i++) {
@autoreleasepool {
SKTexture *texture = [atlas textureNamed:[NSString stringWithFormat:@"sgl%02d.png", i+1]];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:texture];
sprite.position = CGPointMake(300, 70*(i+1));
[self addChild:sprite];
}
}
}
実行すると、テクスチャが使用できていることが分かります。
今回はここまで。