1

I wonder what's wrong with my code, it doesnt show the particles correctly.

enter image description here

and here's the expected particle

enter image description here

implementation

physicsWorld.contactDelegate = self

    self.scene?.backgroundColor = UIColor.blackColor()

    self.scene?.size = CGSize(width: 640, height: 1136)

    self.addChild(SKEmitterNode(fileNamed: "MagicParticle")!)
phenomenon09
  • 65
  • 1
  • 3
  • 9

2 Answers2

1

You should try to safely unwrap the particle file first, just to make sure it cannot be nil

 if let particle = SKEmitterNode(fileNamed: "MagicParticle") {
    particle.position = ...
    addChild(particle)
 }

Its strange thats its not working, looking at your pictures it seems like you do not have a typo. Did you change the default spark.png in the particle effect? Try cleaning your project or maybe delete the effect and create it again if it still doesn't work

As a side note, you can delete the 2 words

 scene?...

You are already in a SKScene, so self is the scene and therefore you can just say

 self.backgroundColor = ...
 self.size = ...

or better

 backgroundColor = ...
 size = ...

As a general good coding practice in swift try to only use "self" when the compiler forces you too. So say

addChild(...)

instead of

self.addChild(...)
crashoverride777
  • 10,581
  • 2
  • 32
  • 56
0

I think you should include also the file's extension, like this.

self.addChild(SKEmitterNode(fileNamed: "MagicParticle.sks")!)
gionti
  • 96
  • 5