카메라를 카메라 중앙에 배치하는 가장 기본적인 방법은 플레이어를 항상 카메라 중앙에 배치하기 위해 그리는 모든 것을 오프셋하는 것입니다. 내 자신의 게임에서, 내가 좌표를 변환하는 기능을 사용
def to_pygame_coords(coords):
# move the coordinates so that 0, 0 is the player's position
# then move the origin to the center of the window
return coords - player.position.center + window.position.center
이에 확장하려면이 절대적으로 플레이어에 위치 아니에요 그래서 대신 상자에 창을 중심으로 할 수 있습니다. 그런 다음 플레이어가 상자를 떠날 경우 상자가 그와 함께 움직일 수 있도록 (따라서 카메라를 움직이는) 상자 중심을 업데이트합니다. (안 부정적인 좌표 테스트)
의사 코드 :
BOX_WIDTH = 320
BOX_HEIGHT = 240
box_origin = player.position.center
def update_box(player_coords):
if player_coords.x - box_origin.x > BOX_WIDTH:
box_origin.x = player_coords.x - BOX_WIDTH
elif box_origin.x - player_coords.x > BOX_WIDTH:
box_origin.x = player_coords.x + BOX_WIDTH
if player_coords.y - box_origin.y > BOX_HEIGHT:
box_origin.y = player_coords.y - BOX_HEIGHT
elif box_origin.y - player_coords.y > BOX_HEIGHT:
box_origin.y = player_coords.y + BOX_HEIGHT
def to_pygame_coords(coords):
# move the coordinates so that 0, 0 is the box's position
# then move the origin to the center of the window
return coords - box_origin + window.position.center
카메라가 플레이어 중앙에 오도록하거나, 플레이어가 가장자리에 올랐을 때 플레이어가 누르는 플레이어 주위의 상자를 가운데에 배치하고 싶습니까? – Darthfett