如果我按向右或向左键,图像不会旋转但会变大。我不知道原因。
阅读评论部分(您不需要阅读其余部分)
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((20,40))
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH/2,HEIGHT/2)
self.speed = 0
self.anglesp = 0
self.angle = 0
def update(self):
print(self.angle)
self.speed = 0
self.anglesp = 0
###### why is this not working?
self.image = pygame.transform.rotate(self.image, math.radians(self.angle))
######
keystate=pygame.key.get_pressed()
if keystate[pygame.K_LEFT]:
self.anglesp = -5
if keystate[pygame.K_RIGHT]:
self.anglesp = 5
self.angle+=self.anglesp
if self.angle>=360:
self.angle = 0
if self.angle<=-360:
self.angle = 0
all_sprites = pygame.sprite.Group()
fox = Player()
all_sprites.add(fox)
running = True
while running:
#event
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#update
all_sprites.update()
#render
screen.fill(BLACK)
all_sprites.draw(screen)
pygame.display.update()
#clock
clock.tick(FPS)
pygame.quit()
QWER qwerqwe [R qwerqwer qwre QWER QWER QWER QWER qwerqwerqwerqwerqwerqwerqwer