'Why does % Window.width with (self.object.uvpos[0] + time) in clock_interval make moving textures work correctly in Kivy

I'm doing a tutorial about making a game, and still in the background period, making moving textures. But I just wonder why the wrapped problem fixed by %Window.width in the line self.cloud_texture.uvpos = {(self.cloud_texture.uvpos[0] + time_passed)%Window.width ,self.cloud_texture.uvpos[1]}

I see no problem when I just do self.cloud_texture.uvpos[0] + time_passed only, but the result told me the difference when it's changing the self.cloud_texture.uvpos[1] too, and starting to get some glitch when resizing window after few seconds.

Can someone give me an explanation so I can apply it to my other apps?

.py file

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.properties import ObjectProperty
from kivy.core.window import Window

class Background(Widget):
    cloud_texture = ObjectProperty(None)
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        
        #create texture
        self.cloud_texture = Image(source="assets/cloud.png").texture
        self.cloud_texture.wrap = "repeat"
        self.cloud_texture.uvsize = {Window.width / self.cloud_texture.width, -1}
    
    def scroll_textures(self,time_passed):
        self.cloud_texture.uvpos =  {(self.cloud_texture.uvpos[0] + time_passed)%Window.width ,self.cloud_texture.uvpos[1]}
        texture = self.property("cloud_texture")
        texture.dispatch(self)
        
from kivy.clock import Clock

class MainApp(App):
    def on_start(self):
        Clock.schedule_interval(self.root.ids.background.scroll_textures, 1/60)
    pass

if __name__ == "__main__":
    MainApp().run()

.kv file

FloatLayout:
    Background:
        id: background
        canvas.before:
            Rectangle:
                size: self.size
                pos: self.pos
                source: "assets/sky.png"
            Rectangle:
                size: self.width, 138
                pos: self.pos[0], self.pos[1] + self.height - 138
                texture: self.cloud_texture

You can find the images I'm using here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source