我不知道为什么上次我这样做时出现这个错误是因为我没有发起pygame,但我这次做了所以我真的不知道错误是什么
现在我得到这个prntscr.com/8rumj5 `````````````````````````````````````````````````` ``````````````````````````````````
import pygame
pygame.init()
pygame.display.set_caption("test")
screen = pygame.display.set_mode((800,600))
x = 0
y = 0
black = (0,0,0)
white = (255,255,255)
red = (200,0,0)
green = (0,200,0)
blue = (0,0,255)
bright_red = (255,0,0)
bright_green = (0,255,0)
gray = (153,153,153)
Player = pygame.image.load("player.png")
clock = pygame.time.Clock()
class player:
def __init__(self ,x, y):
self.x = x
self.y = y
self.width = 32
self.height = 32
def render(self,screen):
screen.blit(Player)
def gameloop():
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.fill(white)
player.render(screen)
pygame.display.update()
clock.tick(60)
gameloop()
pygame.quit()
quit()
答案 0 :(得分:0)
你打电话
player.render(screen(100,100))
但screen
是Surface
。 render
类的player
函数只有一个参数,所以你可能想调用
player.render(screen)
但是,只有player
是player
类的实例时,这才有效。您应该遵循命名约定并命名类Player
以避免混淆和错误,然后使用
# create instance
player = Player(100, 100)
...other stuff...
# call render
player.render(screen)