'why is my room transitions code affecting player movement and not transitioning

I have a large map with camera pointing to a smaller area. I have divided the map into smaller rects as rooms, and if the player collides with one of these rects, the new camera offset should change but it does not. Also, the player is now stuck in mid air when jumping, and returns to ground only when right or left is pressed. I can't see how this is not working. My print statements show the new rect topleft positions to be accurate as the player moves around.

I have included the camera code below, if you need more let me know.

class CameraGroup(pygame.sprite.Group):
    def __init__(self, bg, level_length, level_height):
        super().__init__()
        self.display_surf = pygame.display.get_surface()
        self.offset = pygame.math.Vector2()

        self.level_length = level_length
        self.level_height = level_height

        # upload bg image
        self.bg = bg
        self.bg_surf = pygame.image.load(f'levels/bg/{self.bg}.jpg').convert_alpha()
        self.bg_surf = pygame.transform.scale(self.bg_surf, (level_length, level_height))

        # devide full map by smaller rectangles for rooms
        self.room_rects = []
        for x in range(self.level_length // WIDTH):
            for y in range(self.level_height // HEIGHT):
                self.room_rects.append(pygame.Rect(x * WIDTH, y * HEIGHT, WIDTH, HEIGHT))

        print(self.room_rects)

    def offset_draw(self, player):

        # get new camera position when going into next room
        for rect in self.room_rects:
            if player.hitbox.colliderect(rect):
                self.offset = rect.topleft
                print(self.offset)
    
        #create bg
        self.bg_rect = self.bg_surf.get_rect(topleft = (0, 0))
        self.display_surf.blit(self.bg_surf,(0,0))

        #blit sprites with offset
        for sprite in self.sprites():
            offset = sprite.rect.topleft + self.offset
            self.display_surf.blit(sprite.image, offset)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source