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

Re: [pygame] issue with pygame.rect.inflate_ip()



Hi kevin, hi Lenard,
here is my try :

import pygame
pygame.init()
class Box(pygame.sprite.Sprite):            
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((10, 10))
        self.rect = self.image.get_rect()
b = Box()  
print "initial b.rect : %s     b.rect.center : %s" % (b.rect, b.rect.center)
b.rect.inflate_ip(5, 5)
print "inflated b.rect : %s     b.rect.center : %s\n" % (b.rect, b.rect.center)
c = Box()  
print "initial c.rect : %s     c.rect.center : %s" % (c.rect, c.rect.center)
c.rect.inflate_ip(-5, -5)
print "inflated c.rect : %s     c.rect.center : %s" % (c.rect, c.rect.center)

# outputs :
#
# initial b.rect : <rect(0, 0, 10, 10)>     b.rect.center : (5, 5)
# inflated b.rect : <rect(-2, -2, 15, 15)>     b.rect.center : (5, 5)
#
# initial c.rect : <rect(0, 0, 10, 10)>     c.rect.center : (5, 5)
# inflated c.rect : <rect(2, 2, 5, 5)>     c.rect.center : (4, 4)

I have just said it is different from what is espected ((-2, -2), (13, 13) and (5, 5) or (0, 0), (15, 15) and (7, 7)) for b.rect and b.rect center
And he results are worse with negatives.