python - Pygame, border of image get cut while rotating -
i rotating image in pygame.
my image png , have lot of free space around it. however, when rotate, can see invisible frame around it. how fix ? rotating code
def rot_center(image, angle): """rotate image while keeping center , 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 angle pygame.key.set_repeat(1,1) while 1: screen.fill(white) event in pygame.event.get(): # user did if event.type == keydown , event.key == k_space: counter += 2 perso.image=rot_center(perso.original, counter) #counter define angle print "rotating now" all_group.add(statique_group, zombie_group, perso_group) all_group.draw(screen) pygame.display.flip()
any idea ?
fixed !
perso.image=pygame.transform.rotate(perso.original, angle-90) perso.rect=perso.image.get_rect(center=perso.rect.center)
Comments
Post a Comment