LoginSignup
2
2

More than 5 years have passed since last update.

SpriteKit入門 -13-

Posted at

Texture Atlas について見ていきます。

Xcodeでは、テクスチャが複数に分かれている場合でも、自動的に1枚のテクスチャとして扱えるようにしてくれます。
Texture Atlas を使うことでパフォーマンスも向上するようです。

まず、複数のテクスチャを同じフォルダに入れ、フォルダ名を xxx.atlas のように変更します。

spritekit_13_01.png

フォルダをプロジェクトに追加します。

spritekit_13_02.png

PROJECT の Build Settings に SpriteKit Deployment Options が現れるので、
Enable Texture Atlas Generation を Yes にします。

spritekit_13_03.png

TARGETS の Build Phases で Copy Bundle Resources を見ると、koma.atlas が追加されているのが分かります。

spritekit_13_04.png

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];
        }
    }
}

実行すると、テクスチャが使用できていることが分かります。

spritekit_13_05.png

今回はここまで。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2