4

This is a pretty basic question (Im new with swift and spritekit). So anyway Im adding a particle emitter to a spritenode(call it ball) and adding the ball to my scene. This ball is on top of another spritenode that represents the background. When I run the app, the ball appears fine but the particle emitter doesn't show. The emitter shows fine when I remove the background, but not when I add the background. I will post a code example...

//Background
let background = SKSpriteNode(imageNamed:"Background")
background.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
background.zPosition = 0
self.addChild(background)

//Ball
let ball = SKSpriteNode(imageNamed: "ball")
ball.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
ball.zPosition = 1
ball.physicsBody = SKPhysicsBody(rectangleOfSize: ball.frame.size)
ball.physicsBody?.usesPreciseCollisionDetection = true 


//Emitter
let emitter = SKEmitterNode(fileNamed: "emitter")
emitter.targetNode = self

ball.addChild(emitter)

self.addChild(ball)

Like I said, this seems to be a pretty basic question. I just don't know what Im doing wrong. Just to reiterate, when I run this, the emitter doesn't show. But if I take away the background, the emitter shows.

Thanks For the help :)

Paul
  • 156
  • 9
  • 1
    Could you try setting the `zPosition` of the emitter to a number higher than the background, so the emitter appears on top e.g. `emitter.zPosition = 2` – Mark Brownsword Sep 17 '16 at 23:37

3 Answers3

1

Simple answer - you just need to set your emitter's zPosition to be higher than the background's (but less than the ball). zPosition determines the order in which things are rendered, and the higher the number the later it is rendered (thus putting it on top).

It's also possible that your emitter nodes and your background are the same color so it appears as though it isn't there.

Marshall D
  • 454
  • 3
  • 20
1

So I tried changing the zPosition of emitter and it didn't change anything. But when I changed the zPosition of the background to -1 the emitter showed. I wish I knew why this works haha. But thanks for the suggestions :)

Paul
  • 156
  • 9
  • yeah, be nice if Apple spent some money on documentation, examples, demos and instructions. The reference materials are sparse, at best. – Confused Sep 19 '16 at 13:37
0

I had the same thing happen but when you said it doesn't happen when you comment out the background, I remembered that there is a command in GameViewController that you have to set false. skView.ignoresSiblingOrder = false

judy
  • 1