Reputation: 69
I am creating a game and I am looking for someone to edit my code of why is this crashing with this error code:
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1007351fc)
Here is my code:
import UIKit
import SpriteKit
class Winner: SKScene {
override init(size: CGSize) {
super.init(size: size)
backgroundColor = SKColor (red: CGFloat(248), green: CGFloat(248), blue: CGFloat(248), alpha: CGFloat(255)) //UIColor
var message = "Great 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.size)
self.view?.presentScene(scene, transition:reveal)
}
]))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Upvotes: 2
Views: 1099
Reputation: 35402
There are few lines in your question but I think there should be 2 errors in your code.
The first issue (who caused EXC_BREAKPOINT) could be you write the first lines in :
override init(size: CGSize) {
super.init(size: size)
// here there is your code
}
and this would explain the presence of the method:
required init?(coder aDecoder: NSCoder) {}
in your scene class,
but the current scene could be initialized with the convenience constructor:
public convenience init?(fileNamed filename: String)
where you call the SKS relative file scene. In other words, in your GameViewController
you should have done:
if let scene = SKScene(fileNamed: "GameScene") {}
instead of:
let scene = SKScene(size: self.view.frame.size)
so the compiler crash to the :
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
because your class override (then call) the classic init method.
The second issue is that a SKTransition must be called when a SKScene
object is already presented by an SKView
object, so you could use your code in :
override func didMove(to view: SKView) {
print("GameScene")
// here there is your code
}
Indeed this method is called immediately after a scene is presented by a view.
Upvotes: 1