Mar-22-2020, 04:39 AM
I'm trying to make a background that scrolls in all directions. I'm working from an example for a horizontal scrolling game and adding vertical to it, but I can't get it to work right. It works vertical and horizontally but not diagonally.
Here is the code, could someone give me a pointer on how I can make this work correctly?
Here is the code, could someone give me a pointer on how I can make this work correctly?
def draw(self, screen): self.bgx -= self.player.velocity.x self.bgy -= self.player.velocity.y rel_bgx = self.bgx % self.bg.get_rect().width rel_bgy = self.bgy % self.bg.get_rect().height screen.blit(self.bg, (rel_bgx - self.bg.get_rect().width, self.bgy)) screen.blit(self.bg, (self.bgx, rel_bgy - self.bg.get_rect().height)) if rel_bgx < 800: screen.blit(self.bg, (rel_bgx, self.bgy)) if self.bgx > 0: screen.blit(self.bg, (self.bgx - self.bg.get_rect().width, rel_bgy)) if rel_bgy < 800: screen.blit(self.bg, (self.bgx, rel_bgy)) if self.bgy > 0: screen.blit(self.bg, (rel_bgx, self.bgy - self.bg.get_rect().height))