Scrolling Camera in Pygame is not working properly

I implemented a camera with edges in 2D side scrolling game using Pygame, it is working but sometimes it will scroll for more than it should have, and in case of using different moves that involved movement, sometimes the value will be in float number and it will cause the level to be buggy. I have tried different methods of camera, but none of them worked for me so far. Is there any other way to implement camera, or at least make this one work as intended?

Below is the code for scrolling at x-axis:

   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))


1 Answer

I think there might be some weirdness with using round(diff, 0). That always results in a floating number as a result, even with the 0. If you desire to round to an integer, just use round(diff)

• Although it didn't solve the problem entirely, it certainly helped to mitigate the mess, thanks mate! – Tangtaizong Jan 5 '19 at 11:27