简体   繁体   中英

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.

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM