gpt4 book ai didi

ios - 点击 Sprite 时发生的其他 Action ;如何预防

转载 作者:行者123 更新时间:2023-11-30 13:40:21 24 4
gpt4 key购买 nike

我正在构建一个主要通过点击屏幕(任何地方)来玩的游戏。我目前添加了一个设置按钮,点击该按钮会打开一个设置窗口。

问题是,当点击设置按钮时,游戏中也会发生交互。有什么办法可以防止这种情况发生吗?

我的设置屏幕与设置功能结合使用,并且覆盖触摸通过 bool 表达式开始功能。

游戏是通过添加到 didMoveToView View 中的 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()
}
}
}
}
}

最佳答案

嗯,这里有几个手势识别器在工作。实际上,您不需要向 View 添加识别器来知道是否有人正在点击它。这已经为您处理好了(这就是为什么 touchesBegan 无需添加另一个识别器即可工作的原因)。

我会说删除那个额外的识别器,并将 tapped: 的代码移至您的 touchesBegan

关于ios - 点击 Sprite 时发生的其他 Action ;如何预防,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640446/

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