I am making a game on Pygame with a scrolling background made of tiles. So I made the following code to render them:
def printAllTiles(map, x_scroll, y_scroll):
for i, l in enumerate(map): #map is a double entry table
for j, t in enumerate(l):
if t != None and t != 0:
window.blit(Img.loadImage(Img.findImage(t + ".png", "Tiles")), (j*tile_size+x_scroll, i*tile_size+y_scroll))
Later on, I wanted to be able to resize the display window and all the images in it. This included the tiles. So I modified my code as shown below.
Here, the Img.resizeImage
function does quite the same as pygame.transform.scale
, but with a growth ratio as argument.
def printAllTiles(map, x_scroll, y_scroll):
for i, l in enumerate(map):
for j, t in enumerate(l):
if t != None and t != 0:
current_tile = Img.loadImage(Img.findImage(t + ".png", "Tiles"))
window.blit(Img.resizeImage(current_tile, screen_resize_ratio[0]), (j*tile_size+x_scroll, i*tile_size+y_scroll))
This new code raises a pygame.error: Out of memory
.
In other Stack Overflow questions concerning pygame.transform
and pygame memory, I couldn't find an explanation on how does pygame.transform
use more memory.