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

Re: [pygame] Changing the size of a sprite



Basically, this is what I'm doing - it may be wrong, but I was
encouraged to see the sprites moving:

def main():
	[non-sprite stuff ...]
	sganimals=pygame.sprite.Group()
	[creation of sprites, which add themselves to sganimals]
	allsprites = pygame.sprite.RenderPlain((sganimals))
	while 1:
		[handle changes to map parameters, which
			affect the sprites' positions & sizes...]
		sganimals.update()
		screen.blit(screen,(0,0))	# screen is the surface
		allsprites.draw(screen)
		pygame.display.flip()
		
I'll freely admit I'm not sure that this is the correct or best
method.

Thanks.

Jim Scott wrote:

>What is your draw method?
>
>--- John Hopkin <john.hopkin@brookview.karoo.co.uk> wrote:
>> I'm a newbie to pygame (and to Python), so please bear with me.
>> 
>> I'm trying to change the size and position of a sprite in its "update"
>> method - the position changes fine, but the size stays the same.
>> Here's the code:
>> 
>>     def update(self):
>>         mapx,mapy,mapsize = self.map.PositionAnimal(self.x,self.y)
>>         self.rect.topleft = mapx, mapy
>>         self.rect.width = mapsize
>>         self.rect.height = mapsize
>>         print "updated:", self.rect.width
>> 
>> The PositionAnimal function returns the new position and size of the
>> sprite, and the debug print at the end reflects the new size.  The
>> sprite moves when PositionAnimal tells it to, but stays the same size.
>> 
>> Am I missing something here?  Have I provided enough information?
>
>
>=====
>"'Beware of the man who works hard to learn something, learns it, and finds himself no wiser than before,' Bokonon tells us. 'He is full of murderous resentment of people who are ignorant without having come by their ignorance the hard way.'" -- Kurt Vonnegut, "Cat's Cradle"
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Shopping - with improved product search
>http://shopping.yahoo.com