0

i'm learning how to make a moving backround in pygame. i learnd how to do it horizontal and trying now to do it vertical. My problem is that my loop is not fully working , i manged to make it so the backround moves downward, but it wont make a third / fourth etc screen it just stops after 2 screens. Thank you in advance for the help/ explenation. ^-^

import sys

import pygame

pygame.init()
fps = 60
framepersec = pygame.time.Clock()

white = (255, 255, 255)

screen_width = 400
screen_height = 600

display = pygame.display.set_mode((screen_width, screen_height))
display.fill(white)
pygame.display.set_caption("Backround test")


class Backround():

    def __init__(self):
        self.bgimage = pygame.image.load("image/test.png").convert()
        self.rectbgimg = self.bgimage.get_rect()

        self.bgy1 = 0
        self.bgx1 = 0

        self.bgy2 = -self.rectbgimg.height
        self.bgx2 = 0

        self.moving_speed = 3

    def update(self):
        self.bgy1 += self.moving_speed
        self.bgy2 += self.moving_speed
        if -self.rectbgimg.height >= self.bgy1:
            self.bgy1 = self.rectbgimg.height
        if -self.rectbgimg.height >= self.bgy2:
            self.bgy2 = self.rectbgimg.height

    def render(self):
        display.blit(self.bgimage, (self.bgx1, self.bgy1))
        display.blit(self.bgimage, (self.bgx2, self.bgy2))


backround = Backround()

while True:
    framepersec.tick(fps)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    backround.update()
    backround.render()
    pygame.display.update()

starter
  • 1
  • 1

0 Answers0