Home Ask Login Register

Developers Planet

Your answer is one click away!

n0tis February 2016

Pygame, border of image get cut while rotating

I am rotating an image in pygame.

My image is a png and have a lot of free space around it. enter image description here However, when I rotate, I can see the invisible frame around it. How to fix this ? enter image description here I am rotating it with this code

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

counter = 0 #counter define the angle

while 1:
    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)


any idea ?


n0tis February 2016

fixed !

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

Post Status

Asked in February 2016
Viewed 3,323 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life