I have a pygame script, where there is a map that is larger than the screen (double the size) and I defined it like so
board_surface = p.Surface((1500, 1000))
board_rect = board_surface.get_rect()
I thought that in order to apply zooming I do this:
if event.type == p.MOUSEBUTTONDOWN:
if event.button == 4 or event.button == 5:
zoom = 1.1 if event.button == 4 else 0.9
mx, my = event.pos
left = mx + (board_rect.left - mx) * zoom
right = mx + (board_rect.right - mx) * zoom
top = my + (board_rect.top - my) * zoom
bottom = my + (board_rect.bottom - my) * zoom
board_rect = p.Rect(left, top, right-left, bottom-top)
board_surface = p.transform.smoothscale(board_surface, board_rect.size)
screen.fill((50, 150, 255))
screen.blit(board_surface, board_rect)
And of course blit all the sprites to the new surface
board_surface.blit(bg, (0, 0))
for i in troops:
board_surface.blit(i.image, i.rect.center)
for i in buildings:
board_surface.blit(i.image, i.rect.center)
for i in particles:
board_surface.blit(i.image, i.rect.center)
for i in overlay_group:
board_surface.blit(i.image, i.rect.center)
This has it's issues. Firstly, There is an offset where when ever I do something like if mouse_x == self.rect.centerx
in a sprite's class, its completely off when I actually run it, and I usually have to click far away from the sprite in order for the check to pass. Secondly, The inside of that surface doesn't get scaled with it, which is what is I'm trying to achieve. Video here: Vid That is all.