スプライト画像の変更に関するいくつかの異なる投稿を見てきました。現在の割り当てでは、packman スプライトを作成する必要があり、マウスに追従する必要があります。問題ありません。そのコードは次のとおりです。
class Packman(games.Sprite):
"""Create the packman that is conrolled by the mouse"""
#load the packman image
image_right = games.load_image("snap_right.png") # initial value
image_left = games.load_image("snap_left.png")
show_image = image_right
def __init__(self, x=games.mouse.x, y = games.mouse.y):
"""Initialise packman"""
super(Packman, self).__init__(image = Packman.show_image, x = games.mouse.x, y = games.mouse.y)
def update(self):
"""Move packmans coordinates"""
self.x = games.mouse.x
self.y = games.mouse.y
if self.left < 0:
self.left = 0
if self.right > games.screen.width:
self.right = games.screen.width
#change Packman's direction that he is facing`
ご覧のとおり、2 つの画像を読み込もうとしましたが、一度に 1 つの画像しか表示されません。(2枚の画像を使う代わりに、1枚の画像を左右反転させる方法もあると思います。) このままパックマンを動かせます。ここで、マウスの移動方向に応じて Packman を左/右に向けるビットを追加する必要があります。私のハンドブックでは、キーを押して画像を 180 度回転させる例を示しています。彼の目は底にあります。
マウスの方向に応じてパックマンを反転させる別の方法はありますか? (水平方向の反転、つまり左右のみが必要です)