[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Moving sprites.



well, for now i were enjoying these ones
http://www.cs.iupui.edu/~aharris/pygame/ch04/

--------

On Sun, Jul 27, 2008 at 11:38 PM,  <percivalkelley@xxxxxxxxx> wrote:
> So I've read piman's tutorial and checked out a few others. I'm still
> confused. I don't really understand the process of moving a sprite
> around. I would like to use RenderUpdates and such, but I'm lost.
>
> I basically have a simple script that moves a ship around a background
> (the background is an image.)
>
> To create the sprite I'm using:
>
> class Units(pygame.sprite.Sprite):
>
>        def __init__(self, img, loc1 = 250, loc2 = 250):
>                pygame.sprite.Sprite.__init__(self) #start up sprites
>
>                #locs
>                self.loc1 = loc1
>                self.loc2 = loc2
>
>                #create sprite
>                self.image, self.rect = load_image(img)
>                self.rect.center = [self.loc1, self.loc2]
>
> I create the ship like this:
> self.ship = Units('bship.png')
> self.screen.blit(self.ship.image, self.ship.rect)
>
> To redraw the ship when it moves I'm using this:
>
> self.ship.loc1 = n1 #n1 and n2 are setup earlier in the code that
> looks for key presses and sets the pixel difference
> self.ship.loc2 = n2
> self.ship.rect.center = [self.ship.loc1, self.ship.loc2]
> print self.ship.rect.center
> self.screen.blit(self.bg, (0,0))
> self.screen.blit(self.ship.image, self.ship.rect.center)
> pygame.display.flip()
>
> I'm really pretty confused at this point. I know I'm just doing
> something stupid, but I haven't managed to get any other code working
> to redraw the ship properly when it's moved. I don't have the code
> from when I was doing it wrong, but basically, can someone point me in
> the right direction to changing this over to just redraw the
> appropriate areas?
>
> Thanks, and sorry this was rambling.
>