Associating an SKS File with a Custom Class in SpriteKit

I am new to Swift and I am trying to encode a simple game using SpriteKit.

I am trying to create a main menu page for the start button.

I created a file .sksand .swift(cocoa touch class) with the same name.

I designed .sksas I want, but the cocoa touch class does not work.

.swift:

import SpriteKit

class MenuScene: SKScene {

    var mStartBtn: SKSpriteNode = SKSpriteNode()
    var mLabel: SKLabelNode = SKLabelNode()

    override func didMove(to view: SKView) {
        mStartBtn = self.childNode(withName: "startBtn") as! SKSpriteNode
        mLabel = self.childNode(withName: "label") as! SKLabelNode
        mLabel.text = "Hello.."
    }
}

I tried to change the label on the screen to see if it works, but it will not change, as if the .swift file did not work / was not connected to the .sks file.

+4
source share
1 answer

As you suggested, the SKS file is probably not associated with the fast file.

In Xcode

  • open file sks
  • select scene
  • .
  • Custom Class Inspector
  • MenuScene Custom Class

enter image description here

.

+3

Source: https://habr.com/ru/post/1664765/


All Articles