繁体   English   中英

PYGAME PLAYER 不要,在我运行代码时加载

[英]PYGAME PLAYER DON, LOAD WHEN I RUN THE CODE

嘿伙计们,我尝试使用 pygame 制作游戏,但是当我运行代码时,该播放器不可见,但是当我关闭显示一秒钟的窗口时!!

代码 -

import pygame
# insilize pygame
pygame.init()
# screen load
screen = pygame.display.set_mode((800, 600))  # to set the screen (width,hight)
# title
pygame.display.set_caption("Space Invader")  # to set the game name
# icon
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)  # to set the game icon
# player
playerImg = pygame.image.load('player.png')
playerX = 370
playery = 480
def player():
    screen.blit(playerImg, (playerX, playery))

# game loop
running = True
while running:
# screen rgb
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False  # don't put ':'after variable
player()
pygame.display.update() ```

你没有在你的帖子中缩进你的代码,所以很难说但是我很确定你对player()函数的调用是在if event.type == pygame.QUIT:语句下。 它必须在它之外。 您的代码应如下所示:

import pygame
# insilize pygame
pygame.init()
# screen load
screen = pygame.display.set_mode((800, 600))  # to set the screen (width,hight)
# title
pygame.display.set_caption("Space Invader")  # to set the game name
# icon
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)  # to set the game icon
# player
playerImg = pygame.image.load('player.png')
playerX = 370
playery = 480
def player():
    screen.blit(playerImg, (playerX, playery))

# game loop
running = True
while running:
    # screen rgb
    screen.fill((0, 0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False  # don't put ':'after variable
    player()
    pygame.display.update()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM