我目前正在制作主游戏为SKScene
的游戏,但菜单为UIViewController
。我有一个按钮,当点击时应该从菜单转换到SKScene
。我应该在IBAction
?
我正在运行xcode6 beta 5
。如果这改变了什么。
答案 0 :(得分:0)
只需从故事板中加载视图控制器即可。在它呈现之后。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
MyViewController *lcvc = (MyViewController*)[storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
lcvc.modalPresentationStyle= UIModalPresentationCustom;
[self presentViewController:lcvc animated:YES completion:nil];
答案 1 :(得分:0)
如果您只有一个包含按钮的视图控制器,并且稍后会显示SKScene,则可以实现类似于以下的IBAction:
目标C
- (IBAction) buttonPressed:(UIButton *)button
{
// Remove button from the view
[button removeFromSuperview];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
夫特
@IBAction func buttonPressed(button:UIButton)
{
// Remove button from the view
button.removeFromSuperview()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
如果您有两个视图控制器,一个包含按钮,另一个将显示您的SKScene,那么您不需要IBAction。您只需从按钮到游戏视图控制器创建一个segue即可。在故事板上,右键单击(或按住Control键单击)按钮,然后从触发的分段操作拖动到游戏视图控制器,然后释放鼠标/触控板按钮。