Pygame,图像的边界在旋转时被切割

时间:2016-02-08 15:10:50

标签: python pygame

我在pygame中旋转图像。

我的图片是png并且周围有很多可用空间。 enter image description here 然而,当我旋转时,我可以看到它周围的隐形框架。 如何解决这个问题? enter image description here 我正在使用此代码

旋转它
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()

任何想法?

1 个答案:

答案 0 :(得分:0)

已修复!

perso.image=pygame.transform.rotate(perso.original, angle-90)
perso.rect=perso.image.get_rect(center=perso.rect.center)