Stack Overflow
Stack Overflow

Reputation: 149

Sprite-Kit Error

Im following a tutorial right now and Im getting an error that I do not know how to fix.

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let scene = StartGameScene(size: view.bounds.size)
    let skView = view as! SKView
    skView.showsFPS = true
    skView.showsNodeCount = true
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .ResizeFill
    skView.presentScene(scene)
}

override func prefersStatusBarHidden() -> Bool {
    return true
}
}

On line 8 the let scene = StartGameScene(size: view.bounds.size) is giving me an error:

use of Unresolved Identifier ' StartGameScene'.

I have created a CocoaTouch class and named StartGameScene. I dont know what the issue is. How do I fix it?

Upvotes: 2

Views: 184

Answers (3)

Coding Tunes
Coding Tunes

Reputation: 73

just change StartGameScene to GameScene

Upvotes: 0

Mehul
Mehul

Reputation: 602

The cocoa touch class that you have created has to inherit from SKScene. SKScene is the class in which you define your game's scene. Hence your code should look like:

class StartGameScene: SKScene {

}

If you have already done this, then please make sure there isn't any typographic error.

Upvotes: 0

TheCodeComposer
TheCodeComposer

Reputation: 711

StartGameScene would need to be a class declared like this:

class StartGameScene: SKScene {...}

Either StartGameScene is not declared as an SKScene or the class itself is not declared.

Upvotes: 1

Related Questions