我在pygame中旋转图像。
我的图片是png并且周围有很多可用空间。 然而,当我旋转时,我可以看到它周围的隐形框架。 如何解决这个问题? 我正在使用此代码
旋转它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
perso.image = pygame.image.load("sprites/[shadow]main_char_sprite.png")#.convert_alpha()
perso.image = pygame.transform.scale(perso.image, (80,80))
perso.original=perso.image #besoin d'un originial pour faire la rotation
perso.rect = perso.image.get_rect()
perso.rect.x = 200
perso.rect.y = 200
perso.add(perso_group)
counter = 0 #counter define the angle
pygame.key.set_repeat(1,1)
while 1:
screen.fill(white)
for event in pygame.event.get(): # User did something
if event.type == KEYDOWN and event.key == K_SPACE:
counter += 2
perso.image=rot_center(perso.original, counter) #counter define the angle
print "rotating now"
all_group.add(statique_group, zombie_group, perso_group)
all_group.draw(screen)
pygame.display.flip()
任何想法?
答案 0 :(得分:0)
已修复!
perso.image=pygame.transform.rotate(perso.original, angle-90)
perso.rect=perso.image.get_rect(center=perso.rect.center)