我正在创建我的第一个 SpriteKit 游戏,这就是我想要做的:
1. 移除默认 Main_iphone 和 Main_ipad 故事板
- 从 中删除
Main_iphone
和Main_ipad
列出info.plist
。 Main_iPhone.storyboard
从Main Interface
下 删除deployment 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