I'm new to Swift and I am trying to code a simple game using SpriteKit
.
I'm trying to create a main menu page for the 'start' button.
I made a .sks
file and .swift
(cocoa touch class) files with the same name.
I designed the .sks
as I want it to be, but the cocoa touch class is not working.
.swift code:
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 its working, but it won't change, as if the .swift file is not working/connected to the .sks file.
As you suggested, the SKS file is probably not linked to the swift file.
In Xcode
sks
fileCustom Class Inspector
MenuScene
into the Custom Class
fieldThen try again.
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