swift - Casting an SKSpriteNode in an SKReferenceNode -
i've build scene1 in xcode's scene editor. , i've referenced scene has animation scene1.
now, i'm trying cast-out skspritenode inside skreferencenode. name of skspritenode i'm trying cast, on scene references is: "sc01eyelid".
any suggestions might wrong here?
thank in advance.
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)") } } }
in order access node of skrefference 1 needs put additional "//" in withname statement:
if let somespritenode:skspritenode = misha.childnode(withname: "//sc01eyelid") as? skspritenode {}
so withname: "//sc01eyelid" work access sc01eyelid node.
more info here: https://developer.apple.com/documentation/spritekit/sknode
Comments
Post a Comment