스크롤 구현 :
카메라를 구현하려면 카메라
클래스를 사용하여 게임 세계와 플레이어의 위치를 정의합니다. 그런 다음이 오프셋은 화면에 그려 질 때 모든 게임 엔티티의 위치에 적용됩니다.카메라 클래스 생성 :
클래스 카메라 : 클래스 카메라 : def __init __ (self, camera_func, 너비, 높이) : self.camera_func = camera_func self.state = rect (0, 0, 너비, 높이) def apply (self, target) : return target.rect.move (self.state.topleft) DEF 업데이트 (자체, 대상) : self.state = self.camera_func (self.state, target.rect)
class Camera: def __init__(self, camera_func, width, height): self.camera_func = camera_func self.state = Rect(0, 0, width, height) def apply(self, target): return target.rect.move(self.state.topleft) def update(self, target): self.state = self.camera_func(self.state, target.rect)
def complex_camera (카메라, target_rect) : x = -target_rect.center [0] win_width/2 y = -target_rect.center [1] win_height/2 camera.topleft = (pygame.vector2 ((x, y)) - pygame.vector2 (camera.topleft)) * 0.06 # smoothness coolnes 추가 camary.x = max (-(camera.width-win_width), min (0, camera.x)) camera.y = max (-(camera.height-win_height), min (0, camera.y))) 카메라
추가 고려 사항 :
class Camera: def __init__(self, camera_func, width, height): self.camera_func = camera_func self.state = Rect(0, 0, width, height) def apply(self, target): return target.rect.move(self.state.topleft) def update(self, target): self.state = self.camera_func(self.state, target.rect)
하위 클래스를 사용하여 카메라-해동 스프라이트 그룹을 처리하기위한 하위 클래스를 사용합니다. 필요. 플레이어가 화면 밖으로 나가는 것을 방지하기 위해 레벨 경계를 처리합니다.
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3