ffritz
ffritz

Reputation: 2261

xCode Sprite-Kit - Background Image in every Scene

My GameViewController redirects after start to the Menu Scene, which has white collar as background in its didMoveToView method. After a button press there, it redirects to GameScene, where:

override func didMoveToView(view: SKView) {

    self.addChild(bgImage)
    bgImage.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))

Anyway, this image already shows up in the menu, even though it is not mentioned at all in the code for the menu scene. Furthermore, it blocks 80% of the screen, it is on top of everything, so instead of being a background, it is an image on top of everything.

In the actual GameScene it is also on top of my Game Action, while the 20% of the screen has the grey background (Game Action is still working though).

Any ideas on how to fix this?

Upvotes: 0

Views: 232

Answers (2)

Stefan
Stefan

Reputation: 5451

You can move your image to the background with modifying the z position, like:

   bgImage.zPosition = -10

Upvotes: 1

beyowulf
beyowulf

Reputation: 15321

Probably want to say self.insertChild(bgImage,atIndex:0)

Upvotes: 2

Related Questions