I've implemented a camera with edges in the 2D side scrolling game with Pygame. It works, but sometimes it scrolls longer than expected, and if you use different motions that involve movement, the value is sometimes indicated as a floating number. will make the level buggy. I have tried different camera methods, but none of them has worked for me yet. Is there another way to implement a camera or at least make it work as intended?
You will find below the code allowing to scroll the axis of the x:
if self.rect.right> = 500 and self.in_level.world_shift_x> = - ((self.in_level.total_level_width - (Screen_Width + 32))): diff = self.rect.right - 500 self.rect.right = 500 self.in_level.shift_world_x (round (-diff, 0)) if self.rect.left <= 200 and self.in_level.world_shift_x <= - ((self.speed / 2)): diff = 200 - self.rect.left self.rect.left = 200 self.in_level.shift_world_x (round (diff, 0))