1

I am new in stackoverflow and Swift both. I am doing a skeet game with Swift and SpriteKit and I would like to implement the broken ceramic effect when I touch a object. I have all about it except this effect. I have just created my "Myparticle.sks" and selected the image, the number of particles,... Also, I was trying and I add my emitter node in the didMoveToView() method and I observed that I could see it the effect when the scene is displayed but when I add my emitter node in the touchesBegan() method I didn't see it.

I am a little confused for that.

Thanks!

-------Edit--------

I wrote this code in my Class.

private struct Particle{

    static let untypedEmitter : AnyObject = NSKeyedUnarchiver.unarchiveObjectWithFile(NSBundle.mainBundle().pathForResource("MyParticle", ofType: "sks")!)!;
}

let emitter:SKEmitterNode = Particle.untypedEmitter as! SKEmitterNode

Then I wrote this other in the didMoveToView() method. With this I could see the effect.

emitter.position=CGPoint(x:self.frame.width/2,y:self.frame.height/2)
self.addChild(emitter)

Finally, If I add the emitter as before in my touchesBegan() method I didn't see anything.

Diego
  • 11
  • 2
  • 1
    Welcome to StackOverflow! Could you post the relevant code to help people answer your question? – ABakerSmith Apr 19 '15 at 16:00
  • Thanks!. I hope the code I have just added could help people to answer. – Diego Apr 19 '15 at 16:31
  • Are you only adding the particle effect? Or is there anything else in your scene? – ABakerSmith Apr 19 '15 at 16:44
  • There are more things. Some SKLabelNode()'s for example to show the points that you have just got it and SKSpriteNode()'s (plates) that you can remove it if you touch in some of them increasing by this way the puntuation SKLabelNode in one. I only put this code because the other is going well and it's a little long. – Diego Apr 19 '15 at 16:52
  • Does the node count increase when the emitter code is in `touchesBegan` and you press on the screen? – ABakerSmith Apr 19 '15 at 16:54
  • Yes, when you touch a element(plate) on the screen, the puntuation label is increased even you added the emitter node but when you run on the simulator the particle effect not appear. – Diego Apr 19 '15 at 17:00
  • One more question, are the plates tiling the whole screen? – ABakerSmith Apr 19 '15 at 17:02
  • Don't worry. Ask all the information you need it. Mmm... Not exactly tiling the whole screen. They are appearing and moving from the left side of the screen to the rigth side. – Diego Apr 19 '15 at 17:09

1 Answers1

0

Your problem is possibly your emitter's particles is being displayed behind the other content. To display your particles above the other nodes you can change the emitter's particleZPosition property. For example:

emitter.particleZPosition = 1000

I would recommend looking at Apple's SpriteKit documentation for more information on zPositions: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Nodes/Nodes.html

ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
  • I have just checked your answer in my code and I put it that in the touchesBegan() method and the effect is the same as before. I have just added the emitter node in the didMoveToView() and I could see it. Thanks for the information I would look for something in the page you refer. – Diego Apr 19 '15 at 17:24