4

私は最初の SpriteKit ゲームを作成しています。これが私がやろうとしていることです:

1. デフォルトの Main_iphone および Main_ipad ストーリーボードを削除します

  • から削除Main_iphoneしてMain_ipad出品しinfo.plistます。
  • の下 Main_iPhone.storyboardから削除します。Main Interfacedeployment info

2. 次のコードを AppDelegate.m の下に追加します。didFinishLaunchingWithOptions

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[CMViewController alloc] init];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;

3. viewController.m で SKScene を構成する

-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    //Configure the view.
    SKView* skView = (SKView*)self.view;
    //Create and configure the scene.
    SKScene* scene = [CMHomeScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    //Present the scene.
    [skView presentScene:scene];
 }

ランタイムエラー

-[UIView presentScene:]: 認識されないセレクターがインスタンス 0x155854d0 に送信されました
*** キャッチされない例外 'NSInvalidArgumentException' によりアプリを終了します。理由: '-[UIView presentScene:]: 認識されないセレクターがインスタンス 0x155854d0 に送信されました
**** stack: (0x2c3eac1f 0x39b95c8b 0x2c3f0039 0x2c3edf57 0x2c31fdf8 0x10883d 0x2f8a7433 0x2f2cfa0d 0x2f2cb3e5 0x2f2cb26d 0x2f2cac51 0x2f2caa55 0x2fb0b1c5 0x2fb0bf6d 0x2fb16379 0x2fb0a387 0x32b770e9 0x2c3b139d 0x2c3b0661 0x2c3af19b 0x2c2fd211 0x2c2fd023 0x2f90e3ef 0x2f9091d1 0x10c2d1 0x3a115aaf) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

PS:

  • ストーリーボードを削除したり、info.plist を変更したりしていないときは、すべてのシーンが正常に機能しています。
  • すべてのシーンとビュー コントローラーをプログラムで作成しています。
  • self.view = [[SKView alloc]initWithFrame:self.view.frame]下で初期化を試み ました-(void)loadView
4

2 に答える 2

1

を割り当てましSKView* skView = (SKView*)self.viewた。self.view はSKViewのサブクラスではないと思うので、単純に型キャストすると SKView が UIView を指します。

コードのビルドは成功しますが、SKView が実際の ID (UIView) を nil ポインター SKView の背後に隠していることを SKView が検出するため、実行時エラーが発生することは間違いありません。

3. ビューを次のように変更することをお勧めします。

    - (void)viewWillLayoutSubviews 
    { 
    // Configure the view. 
    SKView* skView = [[SKView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Create and configure the scene. 
    SKScene* scene = [CMHomeScene sceneWithSize:skView.bounds.size]; 
    scene.scaleMode = SKSceneScaleModeAspectFill; 
    // Present the scene. 
    [skView presentScene:scene]; 
[self.view addSubview:skView];
    }
于 2015-03-27T07:21:52.160 に答える