1
bgx = 0
bgx2 = bgx + width
def move():
    bgx -= 40
    bgx2 -= 40
While True:
    if bgx <= width *-1:
        bgx = width
    if bgx2 <= width*-1:
        bgx2 = width

    display.blit(bg,[bgx,bgy])
    display.blit(bc,[bgx2,bgy2])

I am trying to create a scrolling bg , whenever I click a key move function is called

When it's time for the second image with bgx2 to show up on screen ,a glitch like something happens like in the attached image

Glitch that happens

What is the reason for that Is the code drawing a new "second" image every loop instead of scrolling?

(https://i.stack.imgur.com/hudSa.jpg)enter image description here

1 Answers1

0

Use the modulo (%) operator to calculate the coordinates:

bgx = 0
bgx2 = bgx + height

def move():
    global bgx, bgx2 
    bgx = (bgx - 40) % height
    bgx2 = bgx - height
Rabbid76
  • 202,892
  • 27
  • 131
  • 174