嘿伙计们我正在iphone上测试我的游戏,我意识到我的暂停按钮有问题。为什么?因为当我回到游戏时暂停游戏并寻找另一个应用程序时,它不会触摸恢复按钮。 这是代码:
class GameScene: SKScene, SKPhysicsContactDelegate{
var PauseButton = SKSpriteNode(imageNamed: "pause")
var Resume = SKSpriteNode(imageNamed: "resume1")
}
init(size: CGSize, won: Bool) {
super.init(size: size)
//pause
PauseButton.position = CGPointMake(330, 700)
PauseButton.zPosition = 3;
PauseButton.size = CGSizeMake(40, 40);
PauseButton.name = "PauseButton"
self.addChild(PauseButton)
//resume
Resume = SKSpriteNode(imageNamed: "resume1")
Resume.position = CGPointMake(520, 450)
Resume.zPosition = 100
Resume.setScale(1.3)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
show = self.scene as SKScene!
for touch in touches {
let Location:CGPoint = touch.locationInNode(self)
let Node:SKNode = self.nodeAtPoint(Location)
if(Node == PauseButton){
self.show.paused = true
PauseButton.removeFromParent()
self.addChild(Resume)
}
if(Node == Resume){
Resume.removeFromParent()
self.show.paused = false
self.addChild(PauseButton)
}
有任何帮助吗?感谢
答案 0 :(得分:0)
当你回到你的应用程序时,SpriteKit会自动恢复。所以你需要:
第1步:创建一个变量:
var wasPaused : Bool = false
第2步:在暂停/恢复功能中更改它:
wasPaused = true // pause func
wasPaused = false // resume fun
第3步:更新你的场景:
override func update(currentTime: CFTimeInterval) {
if isPausing{
self.paused = true
return
}
}
答案 1 :(得分:0)
暂停视图而不是场景。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
guard let view = view else {
return
}
view.paused = !view.paused
}