I am trying to use surface.blits with the area parameter to improve the performance of my code. When I use the area parameter for blits, I run into the following error:
SystemError: <'method 'blits' of 'pygame.Surface' objects> returned a result with an error set.
If I remove the area parameter, blits work as I would expect. Any ideas on what I could be doing wrong? Attached below is an example code my use case and error.
import sys
import random
import pygame
pygame.init()
tilemap = pygame.image.load('pattern.jpg')
tilesize = 64
size = 4
w, h = size*64, size*64
screen = pygame.display.set_mode((w, h))
while True:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
blit_list = []
for i in range(size):
for j in range(size):
xi, yi = random.randint(0, size), random.randint(0, size)
blit_args = (tilemap, (i*tilesize, j*tilesize),
(xi*tilesize, yi*tilesize, tilesize, tilesize))
# calling screen.blit here works correctly
screen.blit(*blit_args)
blit_list.append(blit_args)
# instead of using multiple blit calls above, calling screen.blits here fails
# remove the area argument (3rd arg) from each blit_arg tuple works
# screen.blits(blit_list)
pygame.display.flip()
# wait a second
pygame.time.wait(1000)
Here is the image I used (https://www.behance.net/gallery/19447645/Summer-patterns):