n0tis February 2016

Pygame, trying to rotate sprite

I'm trying to rotate of sprite for my game written in pygame

I don't get any consol error, but my sprite stay exactly the same and doesn't rotate :(

Any idea ?

perso.image = pygame.image.load("sprites/[shadow]main_char_sprite.png").convert_alpha()
perso.image = pygame.transform.scale(perso.image, (53,60))
perso.rect = perso.image.get_rect()
perso.rect.x = 200
perso.rect.y = 200
perso.add(perso_group)

while 1:
    screen.fill(white)
    pygame.transform.rotate(perso.image,30) ########not working :(





    all_group.add(statique_group, zombie_group, perso_group)
    all_group.draw(screen)


    pygame.display.flip()

Answers


legoscia February 2016

The documentation for the transform functions says:

All these functions take a Surface to operate on and return a new Surface with the results.

So you need to assign the return value of rotate to the variable:

perso.image = pygame.transform.rotate(perso.image,30)

However, the documentation also says:

Some of the transforms are considered destructive. These means every time they are performed they lose pixel data. Common examples of this are resizing and rotating. For this reason, it is better to retransform the original surface than to keep transforming an image multiple times.

So you may want to keep the original, and keep increasing the rotation angle instead.

Post Status

Asked in February 2016
Viewed 2,650 times
Voted 14
Answered 1 times

Search




Leave an answer