首页 > 解决方案 > 无法呼叫玩家

问题描述

我正在尝试制作类似游戏的东西,它是一个宇宙飞船游戏我有图片 spaceship.png 和 player.png 但我看不到玩家我只能看到图标和黑屏

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption("1st game")
icon = pygame.image.load("Spaceship.png")
pygame.display.set_icon(icon)


playerImg = pygame.image.load('player.png')
playerX = 370
playerY = 600


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


running = True
while running:

    screen.fill((0, 0, 0))

    player()

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

    pygame.display.update()

但它只显示黑屏,不显示播放器

标签: pythonpygame

解决方案


屏幕尺寸为 800x600。玩家的 y 坐标为 600。因此玩家在底部的窗口之外。
改变玩家的坐标:

playerY = 600

playerY = 480

推荐阅读