[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] rotating problem



> > I want to rotate a surface in-place clipping anything that would be
> > outside the original rect and keeping the original colorkey and so forth.
> > I think this will make a 'rolling stone' sprite work the way I want.
> > Currently if I try to rotate the stone as it moves it gets the effect of
> > bouncing which is not what I want. This happens even if I center. The
> > original image is dead center and perfectly round so it isn't the image
> > causing the bounce effect. Any suggestions are appreciated. Thanks.
>
> one option would be to use the source clipping option in the blit function.
> a simple function to do it all would be this..
>
>
> def blit_rotated_clipped(dst, src, pos, angle):
>     "blit a rotated image clipped to original size"
>     rot = pygame.transform.rotate(src, angle)
>     srcrect = src.get_rect()
>     secrect.center = rot.get_rect().center
>     dst.blit(src, pos, srcrect)

Thanks, helped a lot. For anyone else working with the same problem this
is the final working copy I ended up looks like this:

def blit_rotated_clipped ( src, angle ):
        srcrect = src.get_rect ()
        colorkey = src.get_colorkey ()

        dst = pygame.Surface ( ( srcrect.right - srcrect.left,
                srcrect.bottom - srcrect.top ) ).convert ()
        dst.set_colorkey ( colorkey, RLEACCEL )
        dst.fill ( colorkey )

        rot = pygame.transform.rotate ( src, angle )
        srcrect.center = rot.get_rect ().center
        dst.blit ( rot, ( 0, 0 ), srcrect )
        return dst

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org