我已经在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)")
}
}
}发布于 2017-07-31 17:32:44
为了访问SKRefference的任何节点,需要在withName语句中添加额外的"//“:
if let someSpriteNode:SKSpriteNode = misha.childNode(withName: "//sc01eyelid") as? SKSpriteNode {}因此,withName:"// sc01eyelid“可以访问sc01eyelid节点。
更多信息请点击此处:https://developer.apple.com/documentation/spritekit/sknode
https://stackoverflow.com/questions/45366452
复制相似问题