【问题标题】:How To Detect Game Over in Top Down View Endless Runner Game in SpriteKit如何在 SpriteKit 中自上而下查看 Endless Runner 游戏中检测游戏结束
【发布时间】:2015-08-15 07:32:57
【问题描述】:
我正在使用 Swift SpriteKit 开发游戏。一切都很好,但唯一让我害怕的是检测到游戏结束。我的游戏如下图所示,它是一个俯视图游戏。
Brown Color is Wood 和 Blue Color(that one looks like water) is River。如果玩家踩到河而不是木头,那么游戏就结束了。
问题是我如何检测它踩到河边。我尝试使用 func didBeginContact 的 SpriteKit 联系人。但它只在启动时被调用,之后即使我踩到它也不再调用。
【问题讨论】:
标签:
swift
sprite-kit
collision-detection
game-physics
【解决方案1】:
我想到了两种可能的方法。
1。 在你的 touchesBegan 中你这样做了。
注意:如果玩家能够在没有交互的情况下掉入河中,这将不起作用。除此之外,它调用 Game Over 有点早。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
if wood.containsPoint(location) {
} else {
// Call Game Over func
}}
2。 在你的更新函数中(这应该一直有效)
override func update(currentTime: NSTimeInterval) {
super.update(currentTime)
if wood.containsPoint(Player.position) {
} else {
// Call Game Over func
}}
更新:代码应该可以工作