i just simply trying to use SKEmitterNode and SKSpriteNode but i'm getting error on second line of my code
startfield.position = CGPoint.init(x:0,y:1200)
and error is like
"fatal error: unexpectedly found nil while unwrapping an Optional value"
Getting 2 times and also this one
"does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled"
i didn't understand optional concept so because of that i'm not able to solve it ..
class GameScene: SKScene {
var startfield : SKEmitterNode!
var player : SKSpriteNode!
override func didMove(to view: SKView) {
startfield = SKEmitterNode(fileNamed: "Starfield")
startfield.position = CGPoint.init(x: 0, y: 1200)
startfield.advanceSimulationTime(10)
self.addChild(startfield)
startfield.zPosition = -1
//define Player
player = SKSpriteNode(imageNamed: "shuttle")
player.position = CGPoint(x: self.frame.width/2, y: player.size.height/2 + 20)
self.addChild(player)
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
Redeclare your
starfield
variable (mistyped asstartfield
?) such that it allows nil values:This is necessary as
SKEmitterNode(fileNamed:)
is an optional initialiser, i. e. one that may returnnil
. Prior to further usage of this variable test if for not being nil, e. g. using aguard
statement:For the remainder of your function
starfield
is non-nil now.