title: How do I animate an image to continuously move across the screen?
body: <p>This code shows the general behavior I'm trying to achieve, but how can I make this continuous so there's no apparent end to the image, with no gaps of white space and a smooth transition?  AND - isn't there a better way to do this???</p>
  <p>Thanks!</p>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
      @State private var xVal: CGFloat = 0.0
      @State private var timer = Timer.publish(every: 0.05, on: .main, in: .common).autoconnect()
  
      var body: some View {
          ZStack {
              Image(&quot;game_background_2&quot;)  //image attached
                  .aspectRatio(contentMode: .fit)
                  .offset(x: xVal, y: 0)
                  .transition(.slide)
                  .padding()
                  .onReceive(timer) {_ in
                      xVal += 2
                      if xVal == 800 { xVal = 0 }
                  }
          }
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ReaT3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ReaT3.png" alt="enter image description here" /></a></p>