2016-05-29 59 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