我一直在尝试为使用Sprite Kit制作的iOS游戏创建入门屏幕。我正在使用ramotion工具包(https://github.com/Ramotion/paper-onboarding)进行相同操作。我不断收到此错误,接口生成器中的Unknown类,并且我已经坚持了很长时间。这是我的GameViewController类的代码:
import UIKit
import SpriteKit
import PaperOnboarding
protocol Controller {
func levelCompleted()
func levelFailed()
}
/* GameViewController is in charge of managing the game. This includes creating and
* changing levels, access to main menu, etc.
*/
var count = 0
class GameViewController: UIViewController, PaperOnboardingDataSource, PaperOnboardingDelegate
{
@IBOutlet var onboardingView: OnboardingView!
@IBOutlet var getStartedButton: UIButton!
@IBAction func playButtonPressed(_ sender: Any)
{
let controller = storyboard!.instantiateViewController(withIdentifier: "actualGame")
initialiseSKScene()
}
var currentLevel: Level? = nil
var config: GameConfiguration?
var skView: SKView?
override func viewDidLoad()
{
super.viewDidLoad()
onboardingView.dataSource = self
onboardingView.delegate = self
}
func initialiseSKScene()
{
let skView = initialiseSKView()
do
{
config = try GameConfiguration(file: "level_json_sample", size: skView.bounds.size)
}
catch let error
{
print("Level cannot be loaded!")
print(error)
}
let teethArray = config!.getTeethByLevel(id: 1)
let objectArray = config!.getObjectsByLevel(id: 1)
print(objectArray[0])
// Use the JSON file to open level 1
currentLevel = Level(size: skView.bounds.size, bgFile: "background2.png",
teethArray: teethArray, otherArray: objectArray, c: self as! Controller)
currentLevel?.scaleMode = SKSceneScaleMode.resizeFill
skView.presentScene(currentLevel)
}
func onboardingItemsCount() -> Int
{
return 3
}
func onboardingItem(at index: Int) -> OnboardingItemInfo
{
let onBoardItem1 = OnboardingItemInfo(informationImage: UIImage(named: "rocket")!,
title: "A Great Rocket Start",
description: "Caramels cheesecake bonbon bonbon topping. Candy halvah cotton candy chocolate bar cake. Fruitcake liquorice candy canes marshmallow topping powder.",
pageIcon: UIImage(named: "rocket")!,
color: UIColor(red: 217/255, green: 72/255, blue: 89/255, alpha: 1),
titleColor: UIColor.white,
descriptionColor: UIColor.white,
titleFont: UIFont(name: "AvenirNext-Bold", size: 24)!,
descriptionFont: UIFont(name: "AvenirNext-Regular", size: 18)!)
let onBoardItem2 = OnboardingItemInfo(informationImage: UIImage(named: "brush")!,
title: "Design your Experience",
description: "Caramels cheesecake bonbon bonbon topping. Candy halvah cotton candy chocolate bar cake. Fruitcake liquorice candy canes marshmallow topping powder.",
pageIcon: UIImage(named: "brush")!,
color: UIColor(red: 106/255, green: 166/255, blue: 211/255, alpha: 1),
titleColor: UIColor.white,
descriptionColor: UIColor.white,
titleFont: UIFont(name: "AvenirNext-Bold", size: 24)!,
descriptionFont: UIFont(name: "AvenirNext-Regular", size: 18)!)
let onBoardItem3 = OnboardingItemInfo(informationImage: UIImage(named: "notification")!,
title: "Stay Up To Date",
description: "Get notified of important updates.",
pageIcon: UIImage(named: "notification")!,
color: UIColor(red: 168/255, green: 200/255, blue: 78/255, alpha: 1),
titleColor: UIColor.white,
descriptionColor: UIColor.white,
titleFont: UIFont(name: "AvenirNext-Bold", size: 24)!,
descriptionFont: UIFont(name: "AvenirNext-Regular", size: 18)!)
return [onBoardItem1,onBoardItem2,onBoardItem3][index]
}
/* Initialises the SKView where we display the game */
private func initialiseSKView() -> SKView
{
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsPhysics = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
skView.isMultipleTouchEnabled = false
return skView
}
/* This method is called by the currentLevel when it is completed */
func levelCompleted() {
// check if there exists a higher level than currentLevel.id
// change to next level or present winning screen
let reveal = SKTransition.flipHorizontal(withDuration: 0.5)
let gameOverScene = GameOverScene(size: skView!.bounds.size, won: false)
skView?.presentScene(gameOverScene, transition: reveal)
}
func onboardingConfigurationItem(_: OnboardingContentViewItem, index _: Int)
{
}
func onboardingWillTransitonToIndex(_ index: Int)
{
if index == 1
{
if self.getStartedButton.alpha == 1
{
UIView.animate(withDuration: 0.2, animations:
{
self.getStartedButton.alpha = 0
})
}
}
}
func onboardingDidTransitonToIndex(_ index: Int)
{
if index == 2
{
UIView.animate(withDuration: 0.4, animations:
{
self.getStartedButton.alpha = 1
})
}
}
/* This method is called by the currentLevel when it is failed */
func levelFailed() {
// present losing screen
let reveal = SKTransition.flipHorizontal(withDuration: 0.5)
let gameOverScene = GameOverScene(size: skView!.bounds.size, won: false)
skView?.presentScene(gameOverScene, transition: reveal)
}
}
我在界面生成器错误中得到Unknown类,并且ViewDidLoad()中的这一行显示: “线程1:致命错误:在展开可选值时意外发现nil”
onboardingView.dataSource = self
我也在界面生成器中检查了我所有的出口和类,它们都是正确的! 非常感谢您的帮助!