Nar*_*hal 14 transitions sprite-kit swift xcode6 ios8
在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];
}
Run Code Online (Sandbox Code Playgroud)
在尝试将我的简单游戏移植到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")
}
Run Code Online (Sandbox Code Playgroud)
但是我不知道要写什么代码来实际转换到另一个场景.问题(S):
谢谢
Mic*_*lum 39
从你的第二个问题开始,这取决于你.如果您愿意,您可以继续遵循Objective-C约定,即每个文件只有一个类,尽管这不是必需的,也不在Objective-C中.话虽这么说,如果你有几个紧密相关的类,但不是由很多代码组成,那么将它们分组在一个文件中是不合理的.只做正确的事情,不要在一个文件中制作大量的代码.
那么对于你的第一个问题......是的,你已经有了很多问题.基本上,从你到达的地方开始,你需要通过它的大小创建GameScene实例:初始化器.从那里,您只需设置属性并调用present.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
guard let location = touches.first?.locationInNode(self),
let scene = scene,
nodeAtPoint(location) == "Game Button" else {
return
}
let transition = SKTransition.reveal(
with: .down,
duration: 1.0
)
let nextScene = GameScene(size: scene.size)
nextScene.scaleMode = .aspectFill
scene.view?.presentScene(nextScene, transition: transition)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22613 次 |
| 最近记录: |