What is a good way to draw images using pygame?
Solution 1:
This is a typical layout:
myimage = pygame.image.load("myimage.bmp")
imagerect = myimage.get_rect()
while 1:
your_code_here
screen.fill(black)
screen.blit(myimage, imagerect)
pygame.display.flip()
Solution 2:
import pygame, sys, os
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((100, 100))
player = pygame.image.load(os.path.join("player.png"))
player.convert()
while True:
screen.blit(player, (10, 10))
pygame.display.flip()
pygame.quit()
Loads the file player.png
.
Run this and it works perfectly. So hopefully you learn something.
Solution 3:
After using blit
or any other update on your drawing surface, you have to call pygame.display.flip()
to actually update what is displayed.