Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Take a look at this post.this post. Basically you can keep the camera position around, and decide where to draw things based on that. I couldn't quite make sense of your game but here are some brief changes I made:

...
total_level_width = len(level[0])*32
total_level_height = len(level)*32
map_size = pygame.Rect(0, 0, total_level_width, total_level_height)
cameraPosition = [0, 0]
#################Objects################



class Camera:
    def __init__(self, players):
        self.left_viewbox = display_width/2 - display_width/8
        self.right_viewbox = display_width/2 + display_width/10

    def follow(self, shift_x):
        cameraPosition[0] += shift_x
        print cameraPosition
        for i in players:   
            i.rect.x += shift_x

...

Whenever you draw an object then you can call blit like this:

screen.blit(self.img, (self.x - cameraPosition[0], self.y - cameraPosition[1], self.w, self.h))

Take a look at this post. Basically you can keep the camera position around, and decide where to draw things based on that. I couldn't quite make sense of your game but here are some brief changes I made:

...
total_level_width = len(level[0])*32
total_level_height = len(level)*32
map_size = pygame.Rect(0, 0, total_level_width, total_level_height)
cameraPosition = [0, 0]
#################Objects################



class Camera:
    def __init__(self, players):
        self.left_viewbox = display_width/2 - display_width/8
        self.right_viewbox = display_width/2 + display_width/10

    def follow(self, shift_x):
        cameraPosition[0] += shift_x
        print cameraPosition
        for i in players:   
            i.rect.x += shift_x

...

Whenever you draw an object then you can call blit like this:

screen.blit(self.img, (self.x - cameraPosition[0], self.y - cameraPosition[1], self.w, self.h))

Take a look at this post. Basically you can keep the camera position around, and decide where to draw things based on that. I couldn't quite make sense of your game but here are some brief changes I made:

...
total_level_width = len(level[0])*32
total_level_height = len(level)*32
map_size = pygame.Rect(0, 0, total_level_width, total_level_height)
cameraPosition = [0, 0]
#################Objects################



class Camera:
    def __init__(self, players):
        self.left_viewbox = display_width/2 - display_width/8
        self.right_viewbox = display_width/2 + display_width/10

    def follow(self, shift_x):
        cameraPosition[0] += shift_x
        print cameraPosition
        for i in players:   
            i.rect.x += shift_x

...

Whenever you draw an object then you can call blit like this:

screen.blit(self.img, (self.x - cameraPosition[0], self.y - cameraPosition[1], self.w, self.h))
Source Link

Take a look at this post. Basically you can keep the camera position around, and decide where to draw things based on that. I couldn't quite make sense of your game but here are some brief changes I made:

...
total_level_width = len(level[0])*32
total_level_height = len(level)*32
map_size = pygame.Rect(0, 0, total_level_width, total_level_height)
cameraPosition = [0, 0]
#################Objects################



class Camera:
    def __init__(self, players):
        self.left_viewbox = display_width/2 - display_width/8
        self.right_viewbox = display_width/2 + display_width/10

    def follow(self, shift_x):
        cameraPosition[0] += shift_x
        print cameraPosition
        for i in players:   
            i.rect.x += shift_x

...

Whenever you draw an object then you can call blit like this:

screen.blit(self.img, (self.x - cameraPosition[0], self.y - cameraPosition[1], self.w, self.h))