Benr783
Benr783

Reputation: 2890

How can I emit particles with a circular trajectory on iOS?

I would like to emit a sequence of particles using iOS that move in a circle. All the particles can start near the same location, and should have some variance in their angle/size/etc like with most particle emitters. But I cannot figure out way to get the particles to move in a circular path. I have tried both SKEmitterNode and CAEmitterLayer but neither of these seem to be able to accomplish what I need.

Upvotes: 0

Views: 184

Answers (1)

Fault
Fault

Reputation: 1294

you can create a SKEmitterNode then have it follow a circular path using SKAction.follow(...)

//circle
let diameter:CGFloat = 150
let rect:CGRect = CGRect(x:0, y:0, width:diameter, height:diameter)
let cgMutablePath = CGMutablePath()
cgMutablePath.addEllipse(in: rect)

//particle emitter
let emitter:SKEmitterNode? = SKEmitterNode(fileNamed: "MyParticle.sks") 
emitter?.targetNode = self
emitter?.run(SKAction.follow(cgMutablePath, speed: 200))
self.addChild(emitter ?? SKNode())

Upvotes: -1

Related Questions