カメラをカメラの中央に配置する基本的な方法は、プレーヤーが常にカメラの中央にくるように、描画するすべてをオフセットすることです。それは絶対にプレーヤー上に位置していないように、あなたの代わりにボックス時にウィンドウを中央にすることができ、この上で展開する
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