Search code examples
pythonpygamepixelscalingresolution

Which is the best way to scale pixel art games with pygame?


Sprites displays like in the image but I would like them to display bigger (without blurring the pixel art). I scaled the Sprites inside enemy and player class (using pygame.transform.scale()), and I tried it but I for sure there's another solution more efficient to that problem; like putting everything in a surface and then scaling the whole surface instead of scaling each element separately.

screen = pygame.display.set_mode((width, height))


while(True):
  player.update()   #updates the character position

  enemy.update()


  # draw
  player_list.draw(screen) #draw player
  enemy_list.draw(screen) #draw enemy


  #pygame.transform.scale(surface, (1,1))
  screen.blit(update_fps(), (10,0))

  pygame.display.flip()

which is the best aproach to this problem?

Game window


Solution

  • I came with a solution:

    To anyone wanting to make a pixel art this may be useful:

    If you made a pixel art it would probably display like this the problem, the scale

    It doesn't matter how many pixels your pixel art has (by the way I recommend using Libre Sprite) just using pygame.transform.scale(surface, (x,y)) where x and y are the dimensions of the screen (in my case screen = pygame.display.set_mode((640, 360)) ) should draw perfectly scaled your pixel art, like this:

    Correct one