【问题标题】:TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method, get_rec errorTypeError:参数 1 必须是 pygame.Surface,而不是 builtin_function_or_method,get_rec 错误
【发布时间】:2021-03-07 21:49:24
【问题描述】:

下面是我搞砸的代码。我可以提供我所有的代码,但在我输入之前一切正常!从第 58、59、60 号线开始

    bd_surface = pygame.image.load('C:/Users/Documents/Python/Flappybird   Project/sprites/bluebird-midflap.png').convert
    bd_surface = pygame.transform.scale2x(bd_surface)
    bd_rect = bd_surface.get_rect(center = (100,512))

这是我的全部代码,以防万一

import pygame
   import sys


   #Have to define drawing the floor

   def draw_fl():
         screen.blit(fl_surface,(fl_x_pos,900))
         screen.blit(fl_surface,(fl_x_pos + 576,900))
   pygame.init()



       #create display surface x= 560 and 1020 is y
       screen = pygame.display.set_mode((576,1024))
       clock = pygame.time.Clock()

   #Flappy bird Variables

   gravity = .25
   bd_movement = 0

   #background image
   firstpng_surface = pygame.image.load('C:/Users/Documents/Python /Flappybird Project/sprites/background-day.png').convert()
   firstpng_surface = pygame.transform.scale2x(firstpng_surface).convert()


   fl_surface= pygame.image.load('C:/Users/Documents/Python/Flappybird    Project/sprites/base.png').convert()
   fl_surface= pygame.transform.scale2x(fl_surface)

   #floor x position
   fl_x_pos = 0



   bd_surface = pygame.image.load('C:/Users/Documents/Python/Flappybird    Project/sprites/bluebird-midflap.png').convert
   bd_surface = pygame.transform.scale2x(bd_surface)
   bd_rect = bd_surface.get_rect(center = (100,512))

    while True:
     
      for event in pygame.event.get():
         if event.type == pygame.QUIT:
             pygame.quit()
             sys.exit()
      
              
              
    #==moving the floor surface forward want to move it to the left
    screen.blit(firstpng_surface,(0,0))
    

    screen.blit(bd_surface,bd_rect)
    fl_x_pos -=1
    draw_fl()
    if fl_x_pos <= -576:
        fl_x_pos = 0
        
 
    #draws on screen
    pygame.display.update()
    clock.tick(120)

错误信息 第 59 行,在 bd_surface = pygame.transform.scale2x(bd_surface)

TypeError:参数 1 必须是 pygame.Surface,而不是 builtin_function_or_method

【问题讨论】:

  • 这是一个错字。你错过了bd_surface = pygame.image.load('C:/Users/Documents/Python/Flappybird Project/sprites/bluebird-midflap.png').convert末尾的括号(()

标签: pygame pygame-surface


【解决方案1】:

这是一个错字。您错过了末尾的括号 (()):

bd_surface = pygame.image.load('C:/Users/Documents/Python/Flappybird Project/sprites/bluebird-midflap.png').convert

bd_surface = pygame.image.load('C:/Users/Documents/Python/Flappybird    Project/sprites/bluebird-midflap.png').convert()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多