[Tutor] Position issue with Pygame

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Tutor] Position issue with Pygame

Greg Nielsen
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

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|

Re: [Tutor] Position issue with Pygame

Hugo Arts
On Tue, Mar 13, 2012 at 6:00 PM, Greg Nielsen
<[hidden email]> 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
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor