0
最近开始一个新的pygame项目,小行星。我一直在努力让图像在光标方向上旋转,这让我感到非常辛苦。任何帮助表示赞赏,这里是旋转到目前为止的代码:pygame旋转问题
import sys, pygame, math, time;
from pygame.locals import *;
spaceship = ('spaceship.png')
mouse_c = ('crosshair.png')
backg = ('background.jpg')
fire_beam = ('beam.png')
pygame.init()
screen = pygame.display.set_mode((800, 600))
bk = pygame.image.load(backg).convert_alpha()
mousec = pygame.image.load(mouse_c).convert_alpha()
space_ship = pygame.image.load(spaceship).convert_alpha()
f_beam = pygame.image.load(fire_beam).convert_alpha()
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
x, y = 357, 300 #position of space_ship, (line 38 btw, second from bottom)
while True:
screen.blit(bk, (0, 0))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == MOUSEBUTTONDOWN and event.button == 1:
print("Left Button Pressed")
elif event.type == MOUSEBUTTONDOWN and event.button == 3:
print("Right Button Pressed")
if event.type == MOUSEMOTION:
clock.tick(60)
x1, y1 = pygame.mouse.get_pos()
x2, y2 = x, y
dx, dy = x2 - x1, y2 - y1
rads = math.atan2(dx, dy)
degs = math.degrees(rads)
pygame.transform.rotate(space_ship, (degs))
print degs #Prints correct output..
pygame.display.update() #the image flickers, but does not rotate
pos = pygame.mouse.get_pos()
screen.blit(mousec, (pos))
screen.blit(space_ship, (375, 300))
pygame.display.update()
那么...你的代码有什么问题? – jazzpi
请修正身份。它在Python中不是可选的。就目前而言,'while True'行后面有一个语法错误 – jsbueno