0
我想創建一些使用粒子的活動圖形,在這裏我發射粒子並更改發射器位置。使用粒子創建一個特殊的圖形?
問題是我無法找到一種方式來將粒子以直線水平排列。他們似乎有一些雪(重力和旋轉)的影響。
有沒有一種方法來繪製一個像從左到右的線的粒子?
func createParticles()
{
let particleEmitter = CAEmitterLayer()
particleEmitter.emitterPosition = CGPoint(x: self.center.x, y: 100)
particleEmitter.emitterShape = kCAEmitterLayerPoint
particleEmitter.emitterSize = CGSize(width: self.frame.size.width, height: 1)
let red = makeEmitterCellWithColor(Globals.sharedInstance.palleteRed)
let green = makeEmitterCellWithColor(Globals.sharedInstance.palleteRed)
let blue = makeEmitterCellWithColor(Globals.sharedInstance.palleteRed)
particleEmitter.emitterCells = [red, green, blue]
self.layer.addSublayer(particleEmitter)
}
func makeEmitterCellWithColor(color: UIColor) -> CAEmitterCell {
let cell = CAEmitterCell()
cell.birthRate = 1
cell.lifetime = 6.0
cell.lifetimeRange = 0
cell.color = color.CGColor
cell.velocity = 100
cell.velocityRange = 220
cell.emissionLongitude = CGFloat(M_PI)
cell.emissionRange = CGFloat(M_PI_4)
cell.spin = 0
cell.spinRange = 0
cell.scaleRange = 0.15
cell.scaleSpeed = -0.05
cell.contents = UIImage(named: "particle")?.CGImage
return cell
}