在 Objective-C 中使用 Sprite-Kit,我可以成功地使用类似以下代码的 Objective-C 代码来启动新场景。
if ([touchedNode.name isEqual: @"Game Button"]) {
SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:1.0];
GameScene *newGameScene = [[GameScene alloc] initWithSize: self.size];
// Optionally, insert code to configure the new scene.
newGameScene.scaleMode = SKSceneScaleModeAspectFill;
[self.scene.view presentScene: newGameScene transition: reveal];
}
尝试将我的简单游戏移植到Swift,目前为止我已经成功了...
for touch: AnyObject in touches {
let touchedNode = nodeAtPoint(touch.locationInNode(self))
println("Node touched: " + touchedNode.name);
let touchedNodeName:String = touchedNode.name
switch touchedNodeName {
case "Game Button":
println("Put code here to launch the game scene")
default:
println("No routine established for this")
}
但我不知道应该写哪段代码才能真正地转换到另一个场景。
问题:- 请问有人能提供一个在Swift中使用SKTransition的例子吗?
- 通常情况下,您是否会像在Objective-C中那样创建另一个“文件”将其他场景的代码放在其中,或者使用Swift意味着我应该采用不同的方法来处理它?
谢谢。