我的xCode项目有问题。我有一个完整的gamecene.swift文件,值代码(600行)。但是代码不会运行。当我在模拟器中运行我的游戏时,模拟器会显示标准的gamecene.sks颜色以及广告,但不会显示任何代码。我已经检查了gamecene.sks中的自定义类是否正确。一切正常,期望使用gamecene.swift代码,它将无法运行。

import UIKit
import SpriteKit
import GameplayKit
import GoogleMobileAds

class GameViewController: UIViewController {


@IBOutlet weak var GoogleBannerView: GADBannerView!
@IBOutlet weak var MainMenu: UIButton!
override func viewDidLoad() {
    super.viewDidLoad()

    GoogleBannerView.adUnitID = "ca-app-pub-13***46014918193/236762****"
    GoogleBannerView.rootViewController = self
    GoogleBannerView.load(GADRequest())


    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 = .resizeFill

            // Present the scene
            view.presentScene(scene)
        }

        view.ignoresSiblingOrder = true

        view.showsFPS = false
        view.showsNodeCount = false
        view.showsPhysics = true
    }



}

override var shouldAutorotate: Bool {
    return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    if UIDevice.current.userInterfaceIdiom == .phone {
        return .allButUpsideDown
    } else {
        return .all
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override var prefersStatusBarHidden: Bool {
    return true
}

}

最佳答案

经过数小时的尝试,我设法解决了该问题。

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

这是工作代码。问题是,我没有指定我应该领导的场景,而是写了我写的
if let scene = SKScene(fileNamed: "GameScene")

简单的解决方法是将“SKScene”更改为我的SKScene名称。
if let scene = GameScene(Filenamed: "GameScene")

希望这可以帮助无数其他人遇到这个问题!

08-26 03:56