即使在 GameScene 的 Update 方法中游戏还没有结束,我也会得到 "You Lose"
I am getting "You Lose" even when the game is not over in Update method of GameScene
我无法理解我的逻辑有什么问题。它似乎工作正常,直到我用一些方法对应用程序进行了一些更改以发现乌龟移动得太快。
我在游戏开始后的几秒钟内收到 "You Lose" 并且计数增加。敌人还没有触及我的精灵节点,它仍然失败了。在过去的 24 小时里,我一直在努力解决这个问题。
代码与 Ray Wenderlich Zombie Conga 相似
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
if lastUpdatedtime > 0 {
dt = currentTime - lastUpdatedtime
} else {
dt = 0
}
lastUpdatedtime = currentTime
//println("\(dt*1000) milliseconds since last update")
//Tartuga.position = CGPoint(x: Tartuga.position.x + 4 , y: Tartuga.position.y)
boundsCheckTartuga()
rotateSprite(Tartuga, direction: CGPoint(x:22, y: 300),rotationRadiansPerSdec: 3)
//stopTartuga()
mandateFall()
if lives <= 0 && !game0ver {
gameOver = true
println("you lose!")
let reveal = SKTransition.flipHorizontalWithDuration(0.5)
}
如果您的变量 lives
和 game0ver
在您的 class 中定义(看起来就是这样),请使用它们的 didSet
钩子来获得通知,当他们被改变了。这样,您可以设置断点并查看调用者,即:
var lives : Int { didSet { println("lives changed to: \(lives)") } }
最终您可以看到 lives
何时更改,并在设置 "by accident" 时追踪游戏中的点。
Srikanth19,
我注意到上面给出的代码中有 2 个不同的变量 gameOver 和 game0ver。
这是在此处粘贴问题时出现的问题,还是您定义了 2 个不同的变量?
如果您没有定义 2 个不同的变量,那么理想情况下您应该得到一个编译时错误。
注意:
如果您没有收到编译时错误,那么您很可能在 2 个实例中将其声明为复制粘贴错误。
在您的声明中检查:
var game0ver: Bool!
并且在代码的其他部分(假设您使用了 Ray Wenderlich 的 Zombie Conga 代码)您可能使用了正确的变量并且它给出了
var gameOver: Bool!
我已经尝试过 Zombie Conga 并参考了代码,您的条件进入的原因之一是 if 条件变量中的错误值....
请分享您的声明部分,或者让我知道您是否能够通过检查 game0ver 中的值来解决此问题(and/or gameOver)
我无法理解我的逻辑有什么问题。它似乎工作正常,直到我用一些方法对应用程序进行了一些更改以发现乌龟移动得太快。
我在游戏开始后的几秒钟内收到 "You Lose" 并且计数增加。敌人还没有触及我的精灵节点,它仍然失败了。在过去的 24 小时里,我一直在努力解决这个问题。
代码与 Ray Wenderlich Zombie Conga 相似
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
if lastUpdatedtime > 0 {
dt = currentTime - lastUpdatedtime
} else {
dt = 0
}
lastUpdatedtime = currentTime
//println("\(dt*1000) milliseconds since last update")
//Tartuga.position = CGPoint(x: Tartuga.position.x + 4 , y: Tartuga.position.y)
boundsCheckTartuga()
rotateSprite(Tartuga, direction: CGPoint(x:22, y: 300),rotationRadiansPerSdec: 3)
//stopTartuga()
mandateFall()
if lives <= 0 && !game0ver {
gameOver = true
println("you lose!")
let reveal = SKTransition.flipHorizontalWithDuration(0.5)
}
如果您的变量 lives
和 game0ver
在您的 class 中定义(看起来就是这样),请使用它们的 didSet
钩子来获得通知,当他们被改变了。这样,您可以设置断点并查看调用者,即:
var lives : Int { didSet { println("lives changed to: \(lives)") } }
最终您可以看到 lives
何时更改,并在设置 "by accident" 时追踪游戏中的点。
Srikanth19,
我注意到上面给出的代码中有 2 个不同的变量 gameOver 和 game0ver。 这是在此处粘贴问题时出现的问题,还是您定义了 2 个不同的变量?
如果您没有定义 2 个不同的变量,那么理想情况下您应该得到一个编译时错误。
注意: 如果您没有收到编译时错误,那么您很可能在 2 个实例中将其声明为复制粘贴错误。
在您的声明中检查: var game0ver: Bool!
并且在代码的其他部分(假设您使用了 Ray Wenderlich 的 Zombie Conga 代码)您可能使用了正确的变量并且它给出了 var gameOver: Bool!
我已经尝试过 Zombie Conga 并参考了代码,您的条件进入的原因之一是 if 条件变量中的错误值....
请分享您的声明部分,或者让我知道您是否能够通过检查 game0ver 中的值来解决此问题(and/or gameOver)