gpt4 book ai didi

swift - 类型 '[SKNode ]' 的值没有成员 'name'

转载 作者:行者123 更新时间:2023-11-30 11:32:48 25 4
gpt4 key购买 nike

我的代码有问题。请在第 5 行帮助我!错误提示:

value of type '[SKNode ]'has no member 'name'

这是我收到错误的函数:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

for touch: AnyObject in touches{
let pointOfTouch = touch.location(in: self)
let nodeITapped = self.nodes(at: pointOfTouch)

if nodeITapped.name == "startButton"{

let sceneToMoveTo = GameScene(size: self.size)
sceneToMoveTo.scaleMode = self.scaleMode
let myTransition = SKTransition.fade(withDuration: 0.5)
self.view!.presentScene(sceneToMoveTo, transition: myTransition)

}

我在 if nodeITapped.name == "startButton"

线上遇到错误

最佳答案

self.nodes(at: pointOfTouch) 返回一个节点数组,因此您应该循环遍历该数组检查每个节点。另外,在找到该节点后,您应该从函数中返回:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

for touch in touches {
let pointOfTouch = touch.location(in: self)
for nodeITapped in self.nodes(at: pointOfTouch) {

if nodeITapped.name == "startButton" {

let sceneToMoveTo = GameScene(size: self.size)
sceneToMoveTo.scaleMode = self.scaleMode
let myTransition = SKTransition.fade(withDuration: 0.5)
self.view!.presentScene(sceneToMoveTo, transition: myTransition)

// found the one I was looking for, so don't continue
return
}

关于swift - 类型 '[SKNode ]' 的值没有成员 'name',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080842/

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