gpt4 book ai didi

ios - SKaction 阻止了 touchesBegan 事件

转载 作者:行者123 更新时间:2023-11-29 01:44:09 31 4
gpt4 key购买 nike

我有一个不同正方形的网格。当用户单击正方形时,该正方形会翻转。但在翻转期间,touchesBegan 事件不起作用。

此代码在点击方 block 后执行:

 func flipTile(node : RectSprite){
let flip = SKAction.scaleXTo(-1, duration: 0.5)
let flip2 = SKAction.scaleXTo(-1, duration: 0.2)

node.setScale(1.0)
var key : String = Array(CircleColor.colors.keys.array)[10]
var changeColor = SKAction.runBlock( { node.texture = SKTexture(imageNamed:"white")})
var removeCombinaison = SKAction.runBlock( {
self.combination.last?.removeFromParent()
self.combination.removeLast()
self.updateGrid()

})

var action = SKAction.sequence([flip, changeColor])
var action2 = SKAction.sequence([flip2, removeCombinaison] )

node.imageName = "white"
node.name = "square"
node.runAction(action)
self.combination.last?.runAction(action2)
}

但是,如果我在下一个方 block 中快速单击,则事件触摸不起作用。也许我需要在新线程中执行这段代码。

最佳答案

您可以尝试使用以下方法检查触摸位置(我认为这甚至可以在翻转动画期间使用):

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */

for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)

if yourNode.containsPoint(location) {
/* called whenever the square is touched */
} else {
/* called when some other location on the screen is touched */
}
}
}

关于ios - SKaction 阻止了 touchesBegan 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32105115/

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