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

Re: [pygame] Changing the size of a sprite



SB wrote:

>I use (and recommend) a loop something like this, I think it's pretty
>simple and self-explanatory.  One problem I had when I was learning was
>that I didn't know that all changes to a sprite's image or rect should
>be done ONLY in (or from) the sprite.update() function.
>
>...
>window = pygame.display.set_mode( (800,600) )
>spriteGroup = RenderUpdates()
>...
>while 1:
>    spriteGroup.clear( window, backgroundImage )
>    spriteGroup.update()
>    dirtyRects = spriteGroup.draw( window )
>    pygame.display.update( dirtyRects )

Thanks - I'll try something like that tomorrow (my Python day's over).

Answering also to Jim Scott here:

Yes, self.image is loaded from a GIF (no drawing, just an image) -
I'll try out changing the image properties tomorrow - thanks.

Just for context, I don't have a background image.  It's a full-screen
app, with a zoomable 512x512 relief map as a surface, which is
generated on the fly by lots of rectangles of various colours to
indicate altitude.  On top of that go the animals, which will (I hope)
soon be moving around and reacting to their environment.  The animals
are represented on-screen as sprites, but their behavioural code will
be separate from the sprite code to allow the program to run at a
higher speed with no graphics.

It's basically a simulation of animals' herding behaviours, etc.  I
feel delighted just to have the relief map and animals displaying
after just a couple of weeks with Python and Pygame.  This is
seriously good stuff.

BTW, the reason for changing the size of the sprites is for zooming in
on a particular area of the map, which will be initiated by the user,
so it's not a big deal if it causes an overhead.  I'm just trying to
keep the sprites' movements and rotations (which are ongoing) as quick
as possible.  If I can get the size changing, rotation is next ....

Again, thanks to both of you.

John