Hello everyone,
I'm trying to make particle effect in SwiftUI, following a YouTube tutorial and this is what I made, despite I wrote the same code as the video, it gives me this error (which doesn't appear in the video). So can anyone tell me what I did wrong?
Here's my code:
And the link for the tutorial:
https://www.youtube.com/watch?v=oj4HEqkDvBY
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Text("Hello, world!")
}
}
struct ParticleEffect: ViewModifier {
let count: Int
let duration: Double = 2.0
@State var time: Double = 0.0
func body(content: Content) -> some View {
let animation = Animation.linear(duration: duration)
.repeatForever(autoreverses: false)
return ZStack {
ForEach(0..<count) { index in
content
.scaleEffect(CGFloat((duration-self.time)/duration))
.modifier(ParticleMotion(time: self.time)) // ERROR: Cannot find 'ParticleMotion' in scope
.opacity((duration-self.time)/duration)
.animation(animation.delay(Double.random(in: 0..<self.duration)))
.blendMode(.plusLighter)
}
.onAppear {
withAnimation() {
self.time = duration
}
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())