gpt4 book ai didi

swift - 返回 GameScene 后 SpriteNodes 搞砸了 (Swift)

转载 作者:行者123 更新时间:2023-11-30 10:18:29 26 4
gpt4 key购买 nike

我有两个场景。游戏场景和游戏场景。 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com