gpt4 book ai didi

swift - 在 for 循环中更改 SKNode 子节点的属性

转载 作者:可可西里 更新时间:2023-11-01 01:06:23 25 4
gpt4 key购买 nike

我知道 SKNode 的子属性是只读属性。不过,有没有一种方法可以在遍历子项时更改这些子项的属性?

例如:

let background = SKSpriteNode(imageNamed: "Background.jpg")   
for child in background.children{
child.position = CGPoint(x: 0, y: 0)
}

最佳答案

您可以将 child 转换到SKNode,然后改变位置。

for child in self.children {
if let sprite = child as? SKNode {
sprite.position = CGPoint(x: 0, y: 0)
}
}

关于swift - 在 for 循环中更改 SKNode 子节点的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28259376/

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