LoginSignup
7
7

More than 5 years have passed since last update.

Empty ApplicationでSpriteKitを使うときにはまるエラー

Last updated at Posted at 2014-03-01

Empty Application TemplateからSprite Kitを使う方法は下記サイトが詳しくわかりやすい。その通り行うだけでうまくいく。

ただし、間違って設定をすると、分かりにくいエラーではまるので、起こった問題をメモしておく。

問題

NSInvalidArgumentExeptionでクラッシュ

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setShowsFPS:]: unrecognized selector sent to instance

SKViewを(SKView *)self.viewというキャストする方法で取得するが、下記の場合にエラーが起こる。

  • self.viewがランタイム時にSKViewではなくてUIView
  • そもそも正しいStoryBoardが使用されていない・読み込まれていない

解決策

下記の点について確認・修正する。

  1. Storyboardが正しく設定されているか
    • プロジェクトの設定で、General -> Deployment Info -> Main Interface にStoryBoardを設定する
    • Screen Shot 2014-03-01 at 11.53.08 PM.png
  2. StoryboardのView Controllerに作成したView Controllerが設定されているか
    • Custom Classに設定する
    • Screen Shot 2014-03-01 at 11.55.02 PM.png
  3. Storyboardで設定したView ControllerのViewがSKViewに設定されているか
    • ViewのCustom ClassでSKViewを指定する
    • Screen Shot 2014-03-01 at 11.59.47 PM.png

参考

http://www.ggkf.com/objective-c/simple-sprite-kit-scene-setup-going-wrong
http://qiita.com/tnantoka/items/5c24e72dc569da1c9b62

画面に何も表示されない時

  • FPS等が表示されず、白い画面しか表示されない。下記のメッセージがコンソールに出力されている Application windows are expected to have a root view controller at the end of application launch

解決策

  1. AppDelegate.mを修正する
// Before
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
// After
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

参考

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