Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36391

Strange SKCameraNode instanciation failure

I tried to create a camera node in my SpriteKit scene like this:

self.camera = SKCameraNode()

and it failed (self.camera was then nil). That was very strange until I tried:

let c = SKCameraNode()
self.camera = c

which then worked!

Could you explain why the first failed while the second succeeded? (Note: that everywhere else the code is exactly the same). Looks like a very strange bug...

Upvotes: 0

Views: 27

Answers (1)

0x141E
0x141E

Reputation: 12753

The camera property of SKScene is a weak variable. You'll need a strong reference to the SKCameraNode or it will be released.

Upvotes: 2

Related Questions