Tom Xue Tom Xue - 1 month ago 12
iOS Question

SpriteKit - didMovetoView is not called

This is my code for the view controller

import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = SKScene(fileNamed: "GameScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
}

view.ignoresSiblingOrder = true

view.showsFPS = true
view.showsNodeCount = true
}
}


And this is my code for the GameScene

import SpriteKit
import GameplayKit

class GameScene: SKScene {
override func didMove(to view: SKView) {
print("gets called")
}


But for some reasons, in the debug area, it didn't print "gets called", which indicates that didMove didn't even get called. What's happening here? Did I miss anything?

Answer

I finally sort that out.

My project name contains a period at the end. Like the name "XXXX.". After several experimentations, I discovered that I can simply solve the problem by removing the period.