Home > OS >  Pygame rect.inflate function does not seem to work
Pygame rect.inflate function does not seem to work

Time:04-18

How does Pygame's "rect.inflate_ip" function work?
In this code, I am trying to inflate this rectangle by some value zoom:

rect = pygame.draw.rect(screen,block.color,(block.x scx,block.y scy,10,10))
rect.inflate_ip(zoom,zoom) 

But this does not have any effect. Why?

CodePudding user response:

Print rect before and after inflate_ip and you'll see the difference. Of course, it doesn't affect the rectangle drawn on the screen. pygame.draw.rect does not generate an object. This function fills a rectangular area on the screen and returns that area. You have to create a pagame.Rect object and use that for drawing. e.g.:

rect = pygame.Rect(block.x scx, block.y scy, 10, 10)
rect.inflate_ip(zoom, zoom) 
pygame.draw.rect(screen, block.color, rect)
  • Related