22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SpriteKit入門 -1-

Last updated at Posted at 2013-10-17

Xcode5で追加されたSpriteKitが面白そうなので触ってみます。
英語は苦手ですが、下記のドキュメントを一通り読んでみるのが目標です。
Sprite Kit Programming Guide

まずは、「Single View Application」でプロジェクトを作成します。
新規Project作成

このあたりの設定はお好きなようにしてください。
ちなみに私はiPhoneは持っていません。
iPadで確認していきます。
Projectオプション

SpriteKitフレームワークを追加します。
SpriteKitフレームワーク追加

ViewControllerの設定でSKViewクラスを選択します。
SKView設定

SpriteKit.hをインポートします。

SpriteViewController.h
# import <UIKit/UIKit.h>
# import <SpriteKit/SpriteKit.h>

@interface SpriteViewController : UIViewController

@end

FPSなどの情報を画面に表示するように設定します。

SpriteViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    SKView *spriteView = (SKView *)self.view;
    spriteView.showsDrawCount = YES;
    spriteView.showsNodeCount = YES;
    spriteView.showsFPS = YES;
}

新しいクラスを追加します。
新規クラス作成

SKSceneクラスを継承してHelloSceneクラスを作成します。
クラス名設定

Class HelloScene
Subclass of SKScene

HelloScene.hをインポートします。

SpriteViewController.m
# import "HelloScene.h"

SKViewにHelloSceneを表示します。

SpriteViewController.m
- (void)viewDidAppear:(BOOL)animated
{
    HelloScene *hello = [[HelloScene alloc] initWithSize:CGSizeMake(768, 1024)];
    SKView *spriteView = (SKView *)self.view;
    [spriteView presentScene:hello];
}

画面は真っ黒ですけど、下端にFPSとか表示されていればとりあえずOKです。
Run

今回はここまで。

22
22
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
22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?