だから私はイメージとして矢印を持っています。よく見ると、中心を中心に回転しているように見えます。しかし、いずれかの方向に回転すると、両側で約 75 度の角度になると、次のエラーが発生します。
何が問題なのかわかりません。pygames Web サイトから回転機能を取得しました。誰かが問題が何であるかを知っているなら、私は本当にあなたの助けに感謝します. コードは次のとおりです。
screen = pygame.display.set_mode(ss)
arrow = pygame.image.load("obj.png").convert_alpha()
x = 400
y= 300
a = 0
turn = 2
def rot_center(image, angle):
"""rotate an image while keeping its center and size"""
orig_rect = image.get_rect()
rot_image = pygame.transform.rotate(image, angle)
rot_rect = orig_rect.copy()
rot_rect.center = rot_image.get_rect().center
rot_image = rot_image.subsurface(rot_rect).copy()
return rot_image
while True:
screen.fill((255, 255, 255))
if turn == 1:
a += 10
if turn == 2:
a -=10
if a == 90:
turn = 2
if a == -90:
turn = 1
rotarrow = rot_center(arrow, a)
screen.blit(rotarrow, (x, y))
pygame.display.update()
sleep(0.1)