2

I made a magnify feature yesterday as a test for a game I'm going to work on. It looks ok but I'd prefer to only zoom in on the area seen through the glass.

Does anybody know how zoom in on a dynamic radius with python/pygame? Will I have to tileset my image or brute force it with some kind of intensive layer blit? I'm not sure whether or not this is something to ask here.

Here's a video demo to show what I'm talking about - https://youtu.be/_pVyb0bns3k

TheJack
  • 111
  • 1
  • 8

1 Answers1

5

I don't think there's any shortcuts here. I would recommend drawing the unzoomed screen as normal, blitting in the zoomed area as a circle, then blitting in the magnifying glass over top. The first and last bits you obviously know how to do already, so let's look at blitting in the zoomed area.

To do this, I would

  • take the portion of the image to be zoomed in as a square, and copy it to a new Surface. (Remember that this will be smaller than the resulting area.)
  • Use pygame.transform.smoothscale to expand it to be large enough to cover the entire magnifying glass area
  • Use masking to turn it from a square into a circle. See Pygame - is there any way to only blit or update in a mask for details.
  • Blit the result.

Don't worry too much about performance. You're only doing this once per frame.

user3757614
  • 1,776
  • 12
  • 10