Reputation: 1579
I have a Swift project including the SpriteKit
framework. When I run the program without anything on it, the screen is black and the node counter at 1. The Main.storyboard
is entirely white and the class in it is set to SKView
. Is the node counter wrong? Shouldn't it be 0 and why is the background black instead of white?
Maybe some necessary code where the mistake is:
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene() // class GameScene is a subclass of SKScene
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = false
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
scene.size = skView.bounds.size
scene.anchorPoint = CGPointMake(0,0);
skView.presentScene(scene)
}
Upvotes: 1
Views: 361
Reputation: 3405
Node counter is right. First of all you set the node couter for skView
object with this line of code:
skView.showsNodeCount = true
Then you add object to this skView
with this line:
skView.presentScene(scene)
This action set node counter to 1
. Your scene is this single node on skView
About black screen: this is default background color for scene, you can change it with this code for example:
scene.backgroundColor = UIColor.redColor()
And your scene will be red
Upvotes: 1