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

Re: [pygame] Error with image.get_rect()




On Jan 14, 2008, at 2:53 PM, marta sanz wrote:

Hi there!
I have a little problem with that function image.get_rect() and that is that after loading an image, I try to obtain its rect but it does nothing...

in my code I do this:
def __init__ (pygame.sprite.Sprite):
	...
	self.counterArea=pygame.Rect(0,0,0,0)
	...

....
def loadCounter(self):
	...
	self.counterImage= pygame.image.load("....")

	self.counterImage= self.counterImage.convert()

	self.counterArea= self.counterImage.get_rect()
	...

and when I do :

print "Top: ", self.counterArea.top
>>>0

Does anyone have any idea of where do my code fails? I have look for examples and info, but all I see seems to say I'm right, so what's wrong?

What happens if you do:

print self.counterArea

instead? Image.get_rect() always returns a rect with a topleft of (0,0). If you want the rect positioned somewhere else, you need to move it afterwards or pass the appropriate parameter to get_rect(), such as center.

-Casey