查看没有块传输的图像,而不是吐出类型的错误

0

的问题

所以我是在看这个教程在线查看作为我非常新来查看. 他所做的是创建一个玩家()功能和那位图传送它。 所以我做相同。 对他来说,他完全混合的,但对我来说,我得到一个类型的错误。 唯一的事情之间有所不同,他的代码和地雷的尺寸的窗口播放器和类和颜色。 我试图寻找它在这里堆溢出,但唯一相关的一个问题是没有得到答复。 不知道哪里出了问题。

完全错误:

/home/Command Blocks/Desktop/venv/bin/python "/home/CommandBlocks/Desktop/CLASS_/Studies/Computer/python/practice/space shooter/main.py"
pygame 2.0.2 (SDL 2.0.16, Python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/Command Blocks/Desktop/CLASS_/Studies/Computer/python/practice/space shooter/main.py", line 33, in <module>
    player()
  File "/home/Command Blocks/Desktop/CLASS_/Studies/Computer/python/practice/space shooter/main.py", line 20, in player
    screen.blit(player, (playerX, playerY))
TypeError: argument 1 must be pygame.Surface, not function

Process finished with exit code 1

完整的代号:

import pygame

#Initialize pygame module
pygame.init()

#Create Screen
screen = pygame.display.set_mode((1000, 600))

#Title and Icon
pygame.display.set_caption("Jungle Invader")
icon = pygame.image.load('fox-sitting.png')
pygame.display.set_icon(icon)

# Player
player = pygame.image.load('cat.png')
playerX = 300
playerY = 500

def player():
    screen.blit(player, (playerX, playerY))


#Main loop
running = True
while running:
    pygame.display.update()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill((244, 232, 255))
    player()
pygame python python-3.x
2021-11-23 13:55:58
1

最好的答案

0

你已经使用的名玩家的两倍。 它是表面返回的 pygame.image.load('cat.png') 和功能, blits 到屏幕上。 重命名的 player 功能 drawPlayer

2021-12-22 18:50:39

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................