【问题标题】:can't call the player无法呼叫玩家
【发布时间】:2021-09-02 04:56:43
【问题描述】:

我正在尝试制作类似游戏的游戏,它是一个宇宙飞船游戏我有图片 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()

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

【问题讨论】:

  • 没关系我的错误是我必须这样做
  • `PlayerY = 370 PlayerX = 480
  • 变量和函数名应该遵循lower_case_with_underscores风格。
  • 检查过你的.pngfile 的路径了吗?

标签: python pygame


【解决方案1】:

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

playerY = 600

playerY = 480

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2012-06-09
    相关资源
    最近更新 更多