gpt4 book ai didi

ios - 检测 SKNode 上的触摸(快速)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:17 25 4
gpt4 key购买 nike

我已经创建了一个容器节点来放入我所有需要一键移动的 SKSpriteNodes,我可以在 iOS 8 中正常检测到它们的触摸,但在 iOS 7 中我只能检测到我的主节点上的触摸以及何时我触摸了一个位于容器节点中的 SKSpriteNode,但没有任何反应。我该如何解决这个问题?

let lvlsNode = SKNode()



override func didMoveToView(view: SKView) {

self.addChild(lvlsNode)

axe = SKSpriteNode(imageNamed:"axe")
axe.anchorPoint = CGPointMake(1, 0)
axe.size = CGSizeMake(axe.size.width/1.4, axe.size.height/1.4)
axe.position = CGPointMake(0+screenWidth/7, shield.position.y-shield.size.width*1.4)
axe.zPosition = 12
axe.name = "axe"
lvlsNode.addChild(axe)
}
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)
let node = nodeAtPoint(location)

if node.name == "axe" {
// do something.... this work in iOS8 but not in iOS 7.1
}

最佳答案

Yournode.name = "nodeX"

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first as UITouch!
if atPoint((touch?.location(in: self))!).name == Yournode.name {
//Your code
}
}

关于ios - 检测 SKNode 上的触摸(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844889/

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