Tom Xue Tom Xue - 5 months ago 40
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() {

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.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?


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.