[Tutor] Position issue with Pygame

Hugo Arts hugo.yoshi at gmail.com
Tue Mar 13 18:55:38 CET 2012


On Tue, Mar 13, 2012 at 6:00 PM, Greg Nielsen
<gollumgreg407366 at gmail.com> wrote:
> Hey everyone,
>
>      Still working on that racing game project. I have come quite a far way
> and will hopefully release something soon, but I wrote some bad code and
> can't seem to fix it. Im most likely just missing something really silly
> because I wrote this code at 2am yesterday. Here it is
>
>     def __init__(self):
>         pygame.sprite.Sprite.__init__(self)
>
>         """Set the image, convert the image, and set the rect"""
>         self.image = pygame.image.load("NoCondition.bmp")
>         self.image = self.image.convert()
>         self.rect = self.image.get_rect()
>
>         """Set the position of the sprite on screen"""
>         self.center = (100, 100)
>         self.rect.center = self.center
>
>      For whatever reason, the sprite is placed at the very top of the screen
> as if assigned "self.rect.topleft = (0, 0)" reguardless of what I assign as
> the position. Please put me out of my misery and point out what little thing
> I coded wrong. Thank you all for the help.
>
> Greg
>

The mistake isn't in this piece of code. It's probably in the piece of
code that does the drawing, I'm guessing in the call to blit(). Make
sure you're using self.rect as the destination of the blit, and the
screen as the surface.

HTH,
Hugo


More information about the Tutor mailing list