我正在尝试制作一个被抛出的球的动画,我希望它旋转并同时遵循平滑的抛物线路径。然而,我似乎无法得到pygame.transform.rotate()
要合作。
到目前为止,这是我尝试过的:
import pygame
screen = pygame.display.set_mode((500, 500))
timer = pygame.time.Clock()
ball = pygame.sprite.Sprite()
ball.image = pygame.image.load("throwball.png")
ball.image = pygame.transform.scale(ball.image, (48,48))
ball.rect = ball.image.get_rect(topleft = (50,50))
ball.orig_image = ball.image
rotaterect = ball.rect
for i in range(60):
#pygame.draw.rect(screen, Color(255,255,255), ball.rect)
ball.image = pygame.transform.rotate(ball.orig_image, i*20)
rotaterect.topleft = (5*i,((i-20)*(i-20) + 1)/5)
ball.rect.center = rotaterect.center
screen.blit(ball.image, ball.rect)
pygame.display.update()
timer.tick(60)
for e in pygame.event.get():
if e.type == pygame.QUIT:
pygame.quit()
sys.exit()
while 1:
for e in pygame.event.get():
if e.type == pygame.QUIT:
pygame.quit()
sys.exit()
Whenever I run the code, the ball moves in an irregular pattern. I made a second rect to try to keep the positioning under control, but the ball ends up forming a path like this:
显然每个框架的定位都有问题,但我不确定为什么任何框架都会不合适,因为它们的位置是由它们的中心点决定的。
这是球的图像:
它是 16x16(正方形),所以我很惊讶为什么图像没有遵循干净的路径。