Bu yüzden pygame için son derece yeni olduğum için pygame hakkında bu öğreticiyi çevrimiçi izliyordum. Yani yaptığı şey bir player () işlevi oluşturmak ve sonra onu patlatmaktı. Ben de aynısını yaptım. Onun için mükemmel bir şekilde karıştırılıyor, ama benim için bir tür hatası alıyorum. Onun koduyla benimki arasında farklı olan tek şey pencerenin boyutları, oyuncu sınıfı ve renkler. Burada yığın taşması'nda aramayı denedim, ancak ilgili tek soru cevapsız kaldı. Yok ne yanlış gitti tabii.
tam hata:
/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
tam kod:
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()