我正在创建一个游戏,以及我想要转换场景的位置。但是,使用过渡的场景时,我收到此错误:如何在SpriteKit中转换场景?
[Graphics] UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once. 3fatal error: unexpectedly found nil while unwrapping an Optional value 2017-01-09 16:58:33.716407 MyGameApp[18371:5784169] fatal error: unexpectedly found nil while unwrapping an Optional value
有谁知道这是怎么回事?
这里是我的代码:
import UIKit
import SpriteKit
class Congrats: SKScene {
override func didMove(to view: SKView) {
backgroundColor = UIColor(red: CGFloat(248), green: CGFloat(248), blue: CGFloat(248), alpha: CGFloat(255)) //SKColor
var message = "Good Job! "
let label = SKLabelNode(fontNamed: "AppleSDGothicNeo-Bold")
label.text = message
label.fontSize = 22
label.fontColor = SKColor.blue
self.backgroundColor = SKColor.black
label.position = CGPoint(x: size.width/2, y: size.height/2)
addChild(label)
run(SKAction.sequence([
SKAction.wait(forDuration: 1.0),
SKAction.run() {
let reveal = SKTransition.flipHorizontal(withDuration: 1.0)
let scene = GameOver(size: (self.view?.frame.size)!)
self.view?.presentScene(scene, transition:reveal)
}
]))
-----
Touching Variable
if countTouch > 10 {
for touch: AnyObject in touches {
let skView = self.view! as SKView
skView.ignoresSiblingOrder = true
var scene: Congrats!
scene = Congrats(size: skView.bounds.size)
scene.scaleMode = .aspectFill
skView.presentScene(scene, transition: SKTransition.doorsOpenHorizontal(withDuration: 1.0))
}
}
OR 此错误。任何人都可以检查它。 PS:我正在让玩家/用户碰到一个粒子,当他们达到他们的极限时,我想过渡到恭喜的场景。任何人都可以检查我是否做得对吗?我相信这是崩溃。
这也是错误代码时崩溃:
0_specialized _fatalerrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never
避免强行拆开可选项。否则,如果基础值为零,您可能会崩溃。此外,当使用初始化程序初始化颜色时,您应该提供0到1之间的范围内的RGBA分量,而不是0和255之间。 – Whirlwind
您能告诉我一些代码,所以我可以理解吗? –
我可以那样做。给我一秒钟打开我的电脑:) – Whirlwind