Pygame ไม่ blitting ภาพแทนที่จะเป็นถุยน้ำลากชนิดข้อผิดพลาด

0

คำถาม

ดังนั้นฉันกำลังจะออกหัดเล่นออนไลน์เรื่อง pygame เหมือนฉันสอบใหม่เพื่อ pygame. ดังนั้นสิ่งที่เขาทำก็คือสร้างเครื่องเล่นฟังก์ชัน()และจากนั้น blit มัน ดังนั้นฉันก็ทำแบบเดียวกัน สำหรับเขาเขาจะถูก blitted แต่สำหรับฉันฉันเข้าใจรูปแบบข้อผิดพลาด สิ่งเดียวที่แตกต่างระหว่างของรหัสและของฉันคือมิติของหน้าต่างและเครื่องเล่นห้องและสี. ฉันพยายามค้นหามันอยู่ในกองเข็เอ่อล้นออกมาแต่คนเดียวที่เกี่ยวข้องถามคำถามคือไม่มีใครตอบกลับมา ไม่แน่ใจว่าเค้าจึงสั่งฆ่าพวกเราทั้งหมด

เต็มไปด้วเกิดข้อผิดพลาด:

/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ý
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่