2012-01-15 44 views
7

我想知道如何使用pygame绘制图像。我知道如何加载它们。 我做了一个空白窗口。 当我使用screen.blit(空白,(10,10))时,它不会绘制图像,而是将屏幕留空。什么是使用pygame绘制图像的好方法?

+2

你有没有用Google搜索'绘制图像pygame'?在我的电脑中,我收到了一些有用的文档和教程 – joaquin 2012-01-15 20:46:35

+0

我们在谈论一种.png类型的图像吗? – 2012-01-15 20:49:24

+0

是它的一个.png文件 – jtl999 2012-01-15 20:56:16

回答

11

这是一个典型的布局:

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() 
2

在您的图面上使用blit或任何其他更新后,您必须致电pygame.display.flip()实际更新显示的内容。

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() 

加载文件 “player.png” 运行这和它完美的作品。所以希望你学到一些东西

相关问题