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

Re: [pygame] Source rect for sprites in a RenderUpdate group



Sounds like you've got a "filmstrip" as your source image. Why not just break the filmstrip up into multiple Surfaces during the __init__ method of your Charactor sprite, and set one of the surfaces to be the "current" self.image?

def breakup_filmstrip(filepath):
 ... (return a list of Surfaces from the source image)
Â
class MyCharactor(Sprite):
 def __init__(...):
ÂÂÂ ...
ÂÂÂ self.all_images = itertools.cycle(breakup_filmstrip('/foo/bar/myfilmstrip.png'))
ÂÂÂ self.image = self.all_images.next()

 def update(...):
ÂÂÂ ...
ÂÂÂ self.image = self.all_images.next()

Shandy

On Fri, Apr 16, 2010 at 7:55 AM, vincent.blazutti <vincent.blazutti@xxxxxxxxxxx> wrote:

With more detail (sorry if that's a noob problem) :
I use a big picture with different view of the plane (the charactor), so I need to display only the good part of the surface. In my crappy version I have 3 attribute for the plane sprite : surface, source rect, and destination rect. Everytime I refresh the screen, I use those attribute to perform the blit().

In the MVC example, for the CharactorSprite, the update() method is overrided, it just move the destination rect, then in the view, the update() method is called, then the draw() method that return modified rect, and then the display.update is done. The draw() method need that rect and image attribute exist in the Sprite object to work. But it does not talk about any source rect to choose only a small part of the surface it's going to draw.

So my question is : is there any already existing attribute in the Sprite class that I can use to specify the source rect that draw() will use ? Or do I have to rewrite the Notify() of the view and replace the draw() method by a blit() one to do so ?

Third option : maybe I don't really understand what the Group.draw() does...





> Message du 16/04/10 16:00
> De : "B W"
> A : pygame-users@xxxxxxxx
> Copie à :
> Objet : Re: [pygame] Source rect for sprites in a RenderUpdate group

>
> Without knowing details, one can only conjecture. You might use Group.update(*args) to get info to each sprite. The sprite group in turn calls Sprite.update(*args). You can pass anything, such as a source rect to use in computing relative offsets, a list or dict of rects, or a callback function.
>
> Gumm
>


Pieddemail