我有两个场景。 GameScene和PlayScene。 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)
}
}
}
然而......当某人在点击"重播"之后被送回GameScene时PlayScene中的按钮,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)
}
}
我不确定这是怎么发生的,但任何形式的帮助都会很棒。谢谢!
答案 0 :(得分:1)
我遇到了同样的问题。您需要设置scaleMode(在此处查看有关" scaleMode&#34的更多信息;)。只需将此代码放在viewDidLoad()中以获取swift:
self.scaleMode = .AspectFill
希望这会有所帮助。