我在Xcode的场景编辑器中构建了一个Scene1。我已经引用了另一个具有此Scene1动画的场景。
现在,我正在尝试删除SKReferenceNode中的SKSpriteNode。 我正在尝试投射的SKSpriteNode的名称是在引用的场景上:“sc01eyelid”。
有什么建议我可能会在这里做错吗?
提前谢谢。
import SpriteKit
import GameplayKit
class Scene1: SKScene {
var misha: SKReferenceNode = SKReferenceNode()
var eyelidForScene1:SKSpriteNode = SKSpriteNode()
override func didMove(to view: SKView) {
castMishaForScene1()
castOutEyelid()
}
//Casting out misha
func castMishaForScene1() {
if let someSpriteNode:SKReferenceNode = self.childNode(withName: "mishaRefNode") as? SKReferenceNode {
misha = someSpriteNode
print("CASTED\(misha)")
}
else {
print("could not cast\(misha)")
}
}
//Casting out eyelid
func castOutEyelid() {
if let someSpriteNode:SKSpriteNode = misha.childNode(withName: "sc01eyelid") as? SKSpriteNode {
eyelidForScene1 = someSpriteNode
print("CASTED\(eyelidForScene1)")
}
else {
print("could not cast\(eyelidForScene1)")
}
}
}
答案 0 :(得分:1)
为了访问SKRefference的任何节点,需要添加额外的" //"在withName语句中:
if let someSpriteNode:SKSpriteNode = misha.childNode(withName: "//sc01eyelid") as? SKSpriteNode {}
所以withName:" // sc01eyelid"可以访问sc01eyelid节点。
更多信息: https://developer.apple.com/documentation/spritekit/sknode