2

I am trying to make a small car game, but I ran into an issue, the background scrolls twice from up to down before it freezes, making weird shapes in the process. For some reason, if the background scrolled from down to up, no errors happen.

here is the code of the scrolling background

def main():
    run = True
    FPS = 60
    clock = pygame.time.Clock()

    BGY = 0
    BGY2 = -BG.get_height()

    def redraw():
        win.blit(BG, (0,BGY-100))
        win.blit(BG, (0,BGY2-100))

        pygame.display.update()
    while run:
        clock.tick(FPS)
        redraw()

        BGY += 2.5
        BGY2 += 2.5
        
        if BGY < BG.get_height() * -1:
            BGY = -BG.get_height()
        if BGY2 < BG.get_height() * -1:
            BGY2 = -BG.get_height()

main()
Community
  • 1
  • 1
Zeperox
  • 196
  • 2
  • 13

1 Answers1

1

The background moves downwards, so the condition has to be:

if BGY > BG.get_height():
    BGY = -BG.get_height()
if BGY2 > BG.get_height():
    BGY2 = -BG.get_height() 

If the back ground has to move upwards, then you have to decrement BGY and BGY2:

BGY -= 2.5
BGY2 -= 2.5

if BGY < BG.get_height() * -1:
    BGY = BG.get_height()
if BGY2 < BG.get_height() * -1:
    BGY2 = BG.get_height() 
Rabbid76
  • 202,892
  • 27
  • 131
  • 174