我是 Swift 和 SKSPRITE 新手
我在我的第一个类 GameScene 上添加了一个按钮:SKScene。单击按钮时,我想移动到新的游戏场景。我怎样才能做到这一点?
我有方法重写 func TouchesBegin(touches:NSSet, withEvent event: UIEvent) { ... }
最佳答案
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
我的答案是从 Ray Wenderlich 教程中删除的:
SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5];
SKScene * myScene = [[YourSceneName alloc] initWithSize:self.size];
[self.view presentScene:myScene transition: reveal];
这不是很快,但应该仍然适用于您的代码。
YourSceneName 应该是您要过渡到的场景的名称。请记住将 header 导入您要从中调用它的类中。
要制作按钮,只需创建一个SKSpriteNode,然后在touchesBegan或Ended中检查触摸位置是否在spriteNode内。如果是,则执行上面发布的代码。
关于swift SKSprite 从一个游戏场景移动到另一个游戏场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25934794/