What is a good way to draw images using pygame?

2020-02-10 05:04发布

I would like to know how to draw images using pygame. I know how to load them. I have made a blank window. When I use screen.blit(blank, (10,10)), it does not draw the image and instead leaves the screen blank.

3条回答
smile是对你的礼貌
2楼-- · 2020-02-10 05:55

After using blit or any other update on your drawing surface, you have to call pygame.display.flip() to actually update what is displayed.

查看更多
冷血范
3楼-- · 2020-02-10 05:59

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()
查看更多
女痞
4楼-- · 2020-02-10 06:05
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.

查看更多
登录 后发表回答