0
我在SpriteKit中制作游戏。我在那里有一个左边的街区和一个右边的街区。起初我以为使用nodeAtPoint与块进行交互,但在我的情况下,对于玩家来说太不舒服。我想这样做,如果玩家触摸屏幕左侧的任何地方 - 它会触发左侧屏蔽,屏幕右侧会相应地触发右侧屏蔽。一个人怎么能这样做呢? 现在我使用节点点交互的代码如下所示:如何在视图中设置触摸位置
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
switch self.nodeAtPoint(location) {
case self.leftblock:
println("closeleft")
leftblock.runAction(SKAction.animateWithTextures(leftArray, timePerFrame: 0.03, resize: true, restore: false))
case self.rightblock:
println("closeright")
rightblock.runAction(SKAction.animateWithTextures(rightArray, timePerFrame: 0.03, resize: true, restore: false))
default: break
}
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
switch self.nodeAtPoint(location) {
case self.leftblock:
println("openleft")
leftblock.runAction(SKAction.animateWithTextures(reversedLeftArray, timePerFrame: 0.03, resize: true, restore: false))
case self.rightblock:
println("openright")
rightblock.runAction(SKAction.animateWithTextures(reversedRightArray, timePerFrame: 0.03, resize: true, restore: false))
default: break
}
}
}
谢谢!这就是我的预期! :) – TimurTim