I have created a fairly simple (at this point, experimental) "game" in XCode using SpriteKit (with Objective-C).
I know how to manually create a SKSpriteNode object and add it to the SKScene - but I am kind of trying to do the opposite - where I created the sprite inside the XCode SceneKit GUI itself (and gave it a name), now I want to retreive it in my code.
In prior experience with XCode, you would do this by declaring a @property UIOutlet [etc] and then connecting it as a referencing outlet inside the IB/Storyboard UI - but I can't find any similar way to do that inside the SpriteKit UI.
I can create a property (as an SKSpriteNode), and name it the same as my SpriteKit object - and it shows up under the SKScene (in the debugger), but is "nil" - i.e. is not "associated" with the object I created in the XCode SpriteKit UI.
Am I missing something - or doing this completely wrong? :-O
If you set the name property of a node in the Sprite Kit Editor, you can access the node, in Swift, by
if let node = self.childNodeWithName("NodeName") as? SKSpriteNode {
// Set up your sprite here
}
or
SKSpriteNode *node = (SKSpriteNode *)[self childNodeWithName:@"NodeName"];
in Obj-C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With