0
我在pygame里做游戏,我有一个有两点的线段。我需要在几秒钟内旋转该段,而不调整它的大小。我怎样才能做到这一点?如何在pygame中旋转线条?
我在pygame里做游戏,我有一个有两点的线段。我需要在几秒钟内旋转该段,而不调整它的大小。我怎样才能做到这一点?如何在pygame中旋转线条?
您可以在这里找到答案:pygame rotating a line
我只用向量。
import sys
import pygame
pygame.init()
SIZE = 640, 480
screen = pygame.display.set_mode(SIZE)
FPSCLOCK = pygame.time.Clock()
startpoint = pygame.math.Vector2(320, 240)
endpoint = pygame.math.Vector2(170, 0)
angle = 0
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
angle = (angle+5) % 360
# The current endpoint is the startpoint vector + the
# rotated original endpoint.
current_endpoint = startpoint + endpoint.rotate(angle)
screen.fill((0, 0, 0))
pygame.draw.line(
screen, pygame.Color("red"), startpoint, current_endpoint, 2)
pygame.display.flip()
FPSCLOCK.tick(30)
pygame.quit()
sys.exit(0)