[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Moving sprites.
thanks! :-)
On Mon, Jul 28, 2008 at 1:06 AM, René Dudfield <renesd@xxxxxxxxx> wrote:
> make sprite.image use the same surface.
>
> Surfaces are not copied by default. You need to use the
> Surface.copy() method to create a new one.
>
> So just assigning the same surface will work for sharing one picture
> with lots of sprites.
>
>
> On Mon, Jul 28, 2008 at 9:33 AM, Paulo Silva <nitrofurano@xxxxxxxxx> wrote:
>> you welcome! :-) - btw, i'm still trying to to on Pygame what i were
>> doing on sdlBasic up to now
>> (http://nitrofurano.linuxkafe.com/sdlbasic), stuff like how to get
>> lots of sprites from just one picture, etc.
>>
>> ------
>>
>> On Mon, Jul 28, 2008 at 12:19 AM, Percival Kelley
>> <percivalkelley@xxxxxxxxx> wrote:
>>> Awesome. Thank you. That did the trick.
>>>
>>> On Sun, Jul 27, 2008 at 1:10 PM, Paulo Silva <nitrofurano@xxxxxxxxx> wrote:
>>>>
>>>> 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.
>>>> >
>>>
>>>
>>
>