2014年07月27日

SpriteKiteのテクスチャアトラスを使用してアニメーションを繰り返す

SpriteKiteで繰り返してアニメーションを表示させる場合、テクスチャアトラスを使用すると簡単にできる。

1. Mac上に、拡張子atlasを持つフォルダを作り、そのフォルダの中にアニメーションさせたい画像ファイルを設置する。

(例)
フォルダ    ファイル
hoge.atlas --- image01.png
       image02.png


2. 上記1.のフォルダごとXcodeにコピーする。

3. Xcodeでプロジェクトの設定「Enable Texture Atlas Generation」を「Yes」にする。

4. コードの修正
- (id)initWithSize:(CGSize)size {
self = [super initWithSize:size];
if (self) {

// テクスチャアトラスからテクスチャを取得
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"hoge"];

SKTexture *p01 = [atlas textureNamed:@"image01"];
SKTexture *p02 = [atlas textureNamed:@"image01"];

// キャラクターを配置
SKSpriteNode *imageNode= [SKSpriteNode spriteNodeWithTexture:p01];
imageNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild: imageNode];

// アニメーションを実行
SKAction *swimAnimation = [SKAction animateWithTextures:@[p01,p02] timePerFrame:0.25];
[pierrot runAction:[SKAction repeatActionForever:swimAnimation]];

}
}


上記のコード例では0.25秒毎に、 image01.png、image02.png の表示を繰り返す。


参考記事:
http://www.raywenderlich.com/ja/51748/sprite-kit-チュートリアル-アニメーションとテクスチャ
http://dev.classmethod.jp/references/ios7-spritekit-texture-atlas/

ラベル:IOS Mac apple iPAD iPhone
posted by mobileDeveloper at 19:39 | Comment(0) | TrackBack(0) | SpriteKit | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。
※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック
×

この広告は90日以上新しい記事の投稿がないブログに表示されております。