SKScene类中的函数未运行

问题描述 投票:0回答:1

我的VC的SceneEditViewController之一有一个SKView,该SKView呈现了我的SKScene AnimationInventory类。要显示AnimationInventory类,用户必须按下PreviewScene按钮。 SceneEditViewController类附加到TabBarController中的第1个场景。

但是,在按下PreviewScene按钮之后,虽然可以识别类属性,但是从我的函数中什至没有显示打印语句。

import UIKit
import Foundation
import SpriteKit
import GameplayKit

class SceneEditViewController: UIViewController, UITabBarControllerDelegate {

    @IBOutlet var animationScreen: SKView!

    @IBAction func previewScene(_ sender: UIButton) {

        let animationScene = AnimationInventory(size: CGSize(width:400, height:400))
        animationScene.scaleMode = .aspectFit
        animationScene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
        animationScene.position = CGPoint(x: 0, y: 0)
        let transition = SKTransition.fade(withDuration: 1.0)

        animationScreen.presentScene(animationScene, transition: transition)
    }

    //Additional code not include but can be if needed
}

class AnimationInventory: SKScene {
    func niceToMeetYou() {
        print("Code Run Check")
    }

    //MARK: Override functions
    override func didMove(to view: SKView) {
        niceToMeetYou()
    }
}
swift sprite-kit
1个回答
0
投票

您没有正确显示场景

[呈现具有在编辑器中创建的关联SKS文件的场景时使用...

if let gameScene = GameScene(fileNamed: "GameScene" {
    gameScene.scaleMode = .aspectFill
    gameScene.isPaused = false //since iOS 10 all scenes are paused by default
    view.presentScene(gameScene)
}

您要设置的自定义高度和宽度将在场景编辑器中设置,或在加载后在代码中进行修改

© www.soinside.com 2019 - 2024. All rights reserved.