TextureAtlas

TextureAtlas in Sprite Kit.
When we use animation, atlas is better performance than usual animation.
How to do in Sprite Kit?

Create atlas image and enable atlas build

We need to create atlas images and save them in same directory named xxx.atlas .atlas is important part.

Copy this atlas directory to your project.
Atlas Directory
Next, you need to set enable to Enable Texture Atlas Generation.
Atlas

Code

AtlasScene.h

#import <SpriteKit/SpriteKit.h>
@interface AtlasScene : SKScene
@end

AtlasScene.m


#import “AtlasScene.h”

@implementation AtlasScene

– (id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
}
return self;
}

– (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Texture
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@”circle”];
SKTexture *p01 = [atlas textureNamed:@”circle_01″];

// Set
UITouch *touch = [touches anyObject];
SKSpriteNode *target = [SKSpriteNode spriteNodeWithTexture:p01];
target.position = [touch locationInNode:self];
[self addChild:target];

NSMutableArray *items = [NSMutableArray array];
[items addObject:p01];

for (int i=2; i < 5; i++) { SKTexture *texture = [atlas textureNamed:[NSString stringWithFormat:@"circle_0%d", i]]; [items addObject:texture]; } [items addObject:p01]; // StartAnimation SKAction *animation = [SKAction animateWithTextures:items timePerFrame:0.25]; [target runAction:animation completion:^{ [target removeFromParent]; }]; } @end [/cpp]

Result

Touch display and emerge circle and start rolling, after rolling this view is disappeared.

Nice Example

I found nice post about it Sprite Kit チュートリアル: アニメーションとテクスチャアトラス