CAEmitterCell does not show colour at all

27 views Asked by At

I have looked for this problem over the internet but unable to find any solution related to my problem.

Here is the code that I wrote so far.

Creating CAEmitterLayer as follows:

    func createParticles() {
        
        let particleEmitter = CAEmitterLayer()

        particleEmitter.emitterPosition = CGPoint(x: self.confettiOuterView.frame.width / 2, y: 0)
        particleEmitter.emitterShape = .line
        particleEmitter.emitterSize = CGSize(width: self.confettiOuterView.frame.size.width, height: 1)
        
        let red = makeEmitterCell(color: .celebration_color_01) // custom color
        let green = makeEmitterCell(color: .celebration_color_02) // custom color
        let blue = makeEmitterCell(color: .celebration_color_03) // custom color

        particleEmitter.emitterCells = [red, green, blue]

        self.confettiOuterView.layer.addSublayer(particleEmitter)
        
    }

Creating each CAEmitterCell as follows:

    func makeEmitterCell(color: UIColor) -> CAEmitterCell {
        
        let cell = CAEmitterCell()
        
        cell.color = color.cgColor // this thing is not working I think
        cell.birthRate = 30
        cell.lifetime = 1.0
        cell.lifetimeRange = 2.0
        cell.velocity = 200
        cell.velocityRange = 100
        cell.emissionLongitude = CGFloat.pi
        cell.emissionRange = CGFloat.pi / 4
        cell.spin = 2
        cell.spinRange = 5
        cell.scale = 0.2
        cell.scaleRange = 0.1
        cell.contents = UIImage(named: "rate-us")?.cgImage
        
        return cell
        
    }

The image I am using is this from this link: https://icons8.com/icon/10276/diamonds

What am I doing wrong here?

0

There are 0 answers