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

Re: [pygame] Rotating Sprites



	I liked your code but I think that generate_rotation should be an
independent function because else you would have an image list for every
object even if they are using  the same sprite. Also what about the rect
sizes. It would be nice if you can make  then always the same size,
because sometimes people would not account for a larger sprite in a
rotation.

Em Sun, 16 Jun 2002 09:45:37 -0700
Pete Shinners <shredwheat@attbi.com> escreveu:

> Leonardo Santagada wrote:
> > thanks but I also want to know how to make the sprite rotations and
> > how to put it in memory to grab it fast. Should I make a for loop
>  > with the rotozoom or use the pygame.transform.rotate and should I
>  > put my images in a list a dict or tuple? why don't pygame already
> > come with a sprite object that do that?
> 
> 
> a simple loop to create the images will likely work best. it might be
> a good idea to include something like this with pygame. if someone
> creates one it should definitely be in the code repository.
> 
> you may also end up preferring pygame.tranform.rotate() over the
> rotozoom function. the straight rotate has cleaner "90 degree"
> rotation than rotozoom, plus rotozoom will convert your image to you
> pixel alphas, which are slower than regular colorkeys. if you do go
> with rotozoom, i recommend calling convert() on the result and
> resetting the proper colorkey?
> 
> in any event, the class would look something like this...
> 
> class RotateSprite(pygame.sprite.Sprite):
>      def __init__(self):
>          pygame.sprite.Sprite.__init__(self)
>          img = pygame.image.load('spriteimage')
>          self.generate_rotations(img, 10)
> 
>      def generate_rotations(self, image, numsteps=5):
>          self.rotates = []
>          for angle in range(0, 360, numsteps):
>              rot = pygame.transform.rotate(image, angle)
>              self.rotates.append(rot)
>          self.angle = 0
>          self.image = self.rotates[0]
>          self.rect = self.image.get_rect()
>          self.numsteps = numsteps
> 
>      def update_rotation(self):
>          oldcenter = self.rect.center
>          pick = (self.angle % 360) / self.numsteps
>          self.image = self.rotates[pick]
>          self.rect = self.image.get_rect()
>          self.rect.center = oldcenter
> 
>      def update(self): #simple animation
>          self.angle += 2
>          self.update_rotation()
> 
> 
> 
> 
> 
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org
> 
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org