问题描述:

i have no clue why i get this error last time i did it was because i didn't initiate pygame, but i did this time so i really dont know what the error is

now i get this 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()

网友答案:

You call

player.render(screen(100,100))

but screen is a Surface. The render function of the player class takes a single argument, so you probably want to call

player.render(screen)

But this would only work if player is an instance of the player class. You should follow the naming convention and name the class Player to avoid confusion and errors, then create an instace of this class with

# create instance
player = Player(100, 100)

...other stuff...

# call render
player.render(screen)
相关阅读:
Top