gpt4 book ai didi

ios - 按位置确定 Sprite 的名称

转载 作者:行者123 更新时间:2023-11-28 11:58:39 26 4
gpt4 key购买 nike

我有很多 SpriteNode:

sharesA.name = "sharesA"
sharesB.name = "sharesB"
sharesC.name = "sharesC"
ect.....

其中一个有一个位置例如:

CGPoint(x: 1159, y: 406)

如何找出这个位置的 Sprite 的名字?

最佳答案

如果您只有坐标,您可以尝试:让名字 = nodeAtPoint(location).name ?? ""

如果你想根据用户触摸来确定,你可以尝试这样的事情:

 class MyScene: SKScene {

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

var touch = touches as! Set<UITouch>
var location = touch.first!.locationInNode(self)
var node = self.nodeAtPoint(location)
let nodeName = node.name
}
}

关于ios - 按位置确定 Sprite 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50427649/

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