【问题标题】:Strange Pygame Error : 'need to be a pygame.Surface'奇怪的 Pygame 错误:'需要成为 pygame.Surface'
【发布时间】:2019-02-03 23:02:21
【问题描述】:

我目前正在使用 Pygame 开发一款游戏,但我在一个非常简单的程序上遇到了一个奇怪的错误

import os, sys, math, time, random, pygame
sys.path.append(os.path.abspath('../lib')) # The program add the folder 'lib' in importable packages
import logs
from constants import *
from definitions import *

pygame.init()
background = pygame.image.load("bg1.png").convert

inProgress = True
a = 1
while inProgress:
    screen.blit(background, (0,0))
    DrawBar(barPos, barSize, borderColor, Very_Light_Blue, (2*a)/max_a)
    a = a + 1
    if a > max_a:
        a = max_a
        for event in pygame.event.get():
            if event.type == pygame.quit:
                inProgess = False
        pygame.display.update()
pygame.quit()

但是回溯告诉我: ' 屏幕中的 14(背景(0,0)),'背景'需要是 Pygame.surface 而不是函数或字典' 有点奇怪... 你能帮帮我吗?

【问题讨论】:

  • .convert 应该是 .convert() 吗?
  • 我,我他妈的傻xD
  • 容易出错:)

标签: python pygame python-3.7


【解决方案1】:

这是一个错字。调用 convert 方法后,您错过了括号:

background = pygame.image.load("bg1.png").convert

background = pygame.image.load("bg1.png").convert()

【讨论】:

  • 请不要回答typo的问题,评论会更好
  • @GameDev 我已投票关闭,这是一个社区 wiki 答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多