Search code examples
iosswiftsprite-kitskscene

Make sprite in GameScene.sks and access it in code


I was making an app in Sprite Kit and I didn't want to design my level in code so I used my GameScene.sks file and visually made my level and I named each of the nodes I made in the GameScene.sks. Now I want to access the nodes in my code that I added in GameScene.sks. How do I for example move a sprite that I made in GameScene.sks.


Solution

  • If you named the nodes, than you can access them within the scene by using

    func childNodeWithName(_ name: String) -> SKNode?
    

    Then you can apply e.g. an SKAction to the node.