使用未声明的类型''Swift ERROR

时间:2017-07-04 18:49:31

标签: xcode7 xcode8

我的快速项目突然停止工作。它引发了错误:

  

使用未声明类型'GameScene'

  

使用未解析的标识符'GameScene'

我的GameViewController文件是:

class GameViewController: UIViewController {

var scene: GameScene!    //Use of undeclared type 'GameScene'

override func viewDidLoad() {
    super.viewDidLoad()

    let skView = view as! SKView
    skView.isMultipleTouchEnabled = false

    scene = GameScene(size: skView.bounds.size)    //Use of unresolved identifier 'GameScene'
    scene.scaleMode = .aspectFill

    skView.presentScene(scene)
}

我的GameScene文件是:

class GameScene: SKScene {

var platform1: Platform!

override func didMove(to view: SKView) {
    scene?.backgroundColor = UIColor(red: 132.0/255.0, green: 179.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    addPlatforms()
}

func addPlatforms() {
    platform1 = Platform()
    platform1.size.width = frame.size.width / 4
    platform1.position = CGPoint(x: platform1.width / 2, y: frame.size.height / 8)
    addChild(platform1)
}

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

在文件顶部,写下import SpriteKitSpriteKit是允许您使用GameScene

的框架

如果有帮助,请告诉我!