我正在構建一個主要通過點擊屏幕(任何地方)進行遊戲的遊戲。我目前添加了一個設置按鈕,當點擊時,打開一個設置窗口。點擊精靈時發生的其他操作;如何防止
問題是,當點擊設置按鈕時,交互也會發生在遊戲中。有什麼辦法可以防止這種情況發生?
我的設置屏幕與設置功能一起使用,覆蓋觸摸開始通過布爾表達式起作用。
遊戲通過添加到didMoveToView視圖中的UITapGestureRecognizer播放。
/* Game Interaction & Playability */
override func didMoveToView(view: SKView) {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("tapped:"))
view.addGestureRecognizer(tap)
}
/* Settings Button Interaction */
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let positionInScene = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(positionInScene)
if let name = touchedNode.name {
if name == "Settings" {
if settingsOpen == false {
settings()
} else {
settings()
}
}
}
}
}
我唯一能想到的就是創建一個更小的視圖並將它放置在屏幕頂部的主視圖上方並將SKSpriteNode按鈕附加到它上面。我會想象,因爲按鈕將成爲不同視圖的一部分,我不會得到水龍頭衝突。但在我進行這一改變之前,如果有人有更簡單的解決方案,我將不勝感激。 – Electric