Skip to content

Instantly share code, notes, and snippets.

@SarahAlsharif
Last active December 5, 2021 22:26
Show Gist options
  • Save SarahAlsharif/798c5e489c075e773fd97a2ac57ba148 to your computer and use it in GitHub Desktop.
Save SarahAlsharif/798c5e489c075e773fd97a2ac57ba148 to your computer and use it in GitHub Desktop.
struct FireworkParticlesGeometryEffect : GeometryEffect {
var time : Double
var speed = Double.random(in: 20 ... 200)
var direction = Double.random(in: -Double.pi ... Double.pi)
var animatableData: Double {
get { time }
set { time = newValue }
}
func effectValue(size: CGSize) -> ProjectionTransform {
let xTranslation = speed * cos(direction) * time
let yTranslation = speed * sin(direction) * time
let affineTranslation = CGAffineTransform(translationX: xTranslation, y: yTranslation)
return ProjectionTransform(affineTranslation)
}
}
@TheGrandPoohbah
Copy link

I think the CGAffineTransform want CGFloat arguments, but the compiler is providing Double. Try this:

    let xTranslation = CGFloat(speed * cos(direction) * time)
    let yTranslation = CGFloat(speed * sin(direction) * time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment