2016-05-29 57 views
0
import pygame 
from sys import exit 
pygame.init() 
screen = pygame.display.set_mode((600,170),0,32) 
pygame.display.set_caption("Hello World!") //set caption 
background = pygame.image.load('bg.jpeg').convert //load picture and convert it 
while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      exit() 
    screen.blit(background,(0,0)) 
    pygame.display.update() //refresh 

我得到的错误:pygame的无法继续成功

File "/Users/huangweijun/PycharmProjects/untitled1/first.py", line 12, in<module>  

    screen.blit(background,(0,0)) 

    TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method 

我有下载pygame的

我不知道如何解决这个问题。

+0

你可以只用'背景= pygame.image.load( “bg.jpeg”)'代替'背景= pygame.image.load( 'bg.jpeg')试试。convert' –

+0

谢谢你。问题解决了 –

+0

所以这基本上意味着你不必转换图像 –

回答

0

函数screen.blit的第一个参数是一个pygame Surface。把它想象成一个可以吸引人的屏幕。您正在指定类Image的对象。这对您无法绘制图像不起作用。

替换backgroundscreen,并添加作为backgroundscreen之间(0,0)一个参数。您的代码现在看起来应该是这样:

import pygame 
from sys import exit 
pygame.init() 
screen = pygame.display.set_mode((600,170),0,32) 
pygame.display.set_caption("Hello World!") //set caption 
background = pygame.image.load('bg.jpeg').convert //load picture and convert it 
while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      exit() 
    screen.blit(screen,background,(0,0)) 
    pygame.display.update() //refresh 
0

菠萝,貌似这里的问题是在这条线:

background = pygame.image.load('bg.jpeg').convert

我想你想用什么: background = pygame.image.load('bg.jpeg').convert_alpha()

希望这就是你正在寻找的!

编辑:你也可以在convert()哎呀!之后加上圆括号! 尝试一下,看看会发生什么!

-Travis