Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pygame rect.inflate function does not seem to work

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading