Skip to content

Instantly share code, notes, and snippets.

@inclement
Created July 11, 2014 00:05
Show Gist options
  • Select an option

  • Save inclement/448b033e96080fefd24d to your computer and use it in GitHub Desktop.

Select an option

Save inclement/448b033e96080fefd24d to your computer and use it in GitHub Desktop.
kivy infinite scrolling image example
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.base import runTouchApp
class Scrolling(Widget):
def __init__(self, **kwargs):
super(Scrolling, self).__init__(**kwargs)
self.canvas.children[-1].texture.wrap = 'repeat'
def update(self, dt):
tcs = self.tex_coords
for i in range(0, 8, 2):
self.tex_coords[i] += dt/3.
root = Builder.load_string('''
Scrolling:
<Scrolling>:
tex_coords: [0, 0, 0, 1, 1, 1, 1, 0]
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'colours.png'
tex_coords: root.tex_coords
''')
Clock.schedule_interval(root.update, 1./60)
runTouchApp(root)
@kkawabat
Copy link
Copy Markdown

kkawabat commented Jan 25, 2020

Thank you for this example, I was struggling on how to create a texture scroll. However I had to make some slight edit to make your example work.

from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.base import runTouchApp


class Scrolling(Widget):
    def __init__(self, **kwargs):
        super(Scrolling, self).__init__(**kwargs)
        Clock.schedule_once(self.texture_init, 0)
        Clock.schedule_interval(self.update, 1. / 60)

    def texture_init(self, dt):
        self.canvas.children[-1].texture.wrap = 'repeat'

    def update(self, dt):
        for i in range(0, 8, 2):
            self.tex_coords[i] += dt/3.

root = Builder.load_string('''
Scrolling:

<Scrolling>:
    tex_coords: [0, 0, 0, 1, 1, 1, 1, 0]
    canvas:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'colours.png'
            tex_coords: root.tex_coords
''')

Clock.schedule_interval(root.update, 1./60)

runTouchApp(root)

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