我有两个场景。游戏场景和游戏场景。 GameScene 更像是“主屏幕”,而 PlayScene 是实际游戏发生的地方。转换到 PlayScene 时一切正常。
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.playbutton {
let scaleDown = SKAction.scaleBy(0.01, duration: 1.0)
self.playbutton.runAction(scaleDown)
var scene = PlayScene(size: self.size)
let skView = self.view as SKView!
scene.size = skView.bounds.size
let transition = SKTransition.pushWithDirection(SKTransitionDirection.Left, duration: 3)
transition.pausesOutgoingScene = false
skView.presentScene(scene, transition: transition)
}
}
}
但是...当有人在 PlayScene 中点击“重播”按钮后被送回 GameScene 时,GameScene 中的所有节点都会困惑。它们的尺寸被放大,甚至一个节点向后反转。
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
isFingerTouching = true
if self.nodeAtPoint(touchLocation) == self.facebookButton {
facebookButtonPushed()
}
if self.nodeAtPoint(touchLocation) == self.twitterButton {
twitterButtonPushed()
}
if self.nodeAtPoint(touchLocation) == self.replay {
var scene = GameScene(size: self.size)
let skView = self.view as SKView!
scene.size = skView.bounds.size
let transition = SKTransition.crossFadeWithDuration(1.0)
transition.pausesOutgoingScene = false
skView.presentScene(scene, transition: transition)
}
}
我不确定这是如何发生的,但任何形式的帮助都会很棒。谢谢!
最佳答案
我也遇到过同样的问题。您需要设置scaleMode (在此处查看有关“scaleMode”的更多信息)。只需将此代码放入 viewDidLoad() 即可:
self.scaleMode = .AspectFill
希望这有帮助。
关于swift - 返回 GameScene 后 SpriteNodes 搞砸了 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28759975/