user6818154
user6818154

Reputation:

Getting an error when transitioning scenes? - SpriteKit

I am making a game with SpriteKit, when I transition scenes the game crashes with a error:

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1007351fc).

Here is my code to see what is going on:

  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)                
    }

Another error during the crash is:

[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

The way I transition scenes:

  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))

Another error when transitioning scenes:

The error:

fatal error: unexpectedly found nil while unwrapping an Optional value 2017-01-10 22:45:56.200385 MyNewApp[20313:6167168] fatal error: unexpectedly found nil while unwrapping an Optional value

Upvotes: 0

Views: 319

Answers (1)

Nikola Bozhkov
Nikola Bozhkov

Reputation: 76

I created a new project and pasted your exact same code, but I didn't get any errors. I only had to add the missing braces.

About the [Graphics] warning, it is because you are trying to create a color with components greater than 1.0, here:

backgroundColor = UIColor(red: CGFloat(248), green: CGFloat(248), blue: CGFloat(248), alpha: CGFloat(255)) //SKColor

You need to use values between 0.0 and 1.0, so you should do this:

backgroundColor = UIColor(red: 248.0/255.0, green: 248.0/255.0, blue: 248.0/255.0, alpha: 1.0) //SKColor

Upvotes: 0

Related Questions