Reputation: 4292
I am in the process of learning SpriteKit, in particular how to apply an SKEmitterNode effect to an existing SKSpriteNode.
I played around in the particle editor and made a simple "rain" particle. I then connected that to an existing sprite in my game like so:
let emitter = SKEmitterNode(fileNamed: "RainParticle.sks")
emitter?.targetNode = dogSprite
// dogSprite is just an SKSpriteNode
dogSprite.addChild(emitter!)
What I get is an effect that looks like this:
The particle effect is applied as I would expect and effect is what I'm going for. The only thing I wish to change is the "area" of the particle effect.
The dog sprite is 60x50, roughly. I'd like the particle effect to get "cut off" at the bottom of the dog sprite. In other words, I don't want the particles to travel outside the "tile" of the dog sprite.
Is there a way to do this by changing properties on the emitter or do I have to come at this problem from a different angle? Thanks so much!
(Just in case anyone happens to notice, none of this artwork is mine and this is not a commercial project. I simply grabbed some sprites I liked off the web to learn with! I am all for complying with licenses.)
Upvotes: 1
Views: 311
Reputation: 35392
You simply could create a SKCropNode
like this example:
// initialize the SKCropNode
let cropNodeDog = SKCropNode.init()
// create the dog sprite and give a position
let dogSprite = SKSpriteNode(imageNamed: "dogSprite.png")
dogSprite.position = CGPoint(x: CGRectGetMidX(self.frame),y:CGRectGetMidY(self.frame))
// create the SKEmitterNode and give a high zPosition
emitter = SKEmitterNode(fileNamed: "RainParticle.sks")
emitter.zPosition = 2
// Define the SKCropNode mask and add elements to it
cropNodeDog.maskNode = dogSprite
cropNodeDog.addChild(dogSprite)
cropNodeDog.addChild(emitter)
//Finally add the SKCropNode to the scene
addChild(cropNodeDog)
You can find more details about SKCropNode
to the Apple docs.
Upvotes: 1
Reputation: 10674
I guess you will have to play around with some settings in the xCode particle editor.
The values that are most likely be of relevance for this are
1) Lifetime
2) PositionRange (y)
You can also change the scale of the particle effect if thats what you need. I do this in code
emitter.setScale(...)
Hope this helps
Upvotes: 0