首页 > 解决方案 > screen.blit 函数在 pygame 中不起作用

问题描述

import pygame, sys

WINDOW_SIZE = (900, 700)
screen = pygame.display.set_mode(WINDOW_SIZE, 0, 32)
pygame.display.set_caption('Pygame Program')
pygame.display.set_icon(pygame.image.load('spaceship (3).png'))

player_img = pygame.image.load('ClipartKey_738895_adobespark.png')
player_X = 130
player_Y = 750
def player():
    screen.blit(player_img, (player_X, player_Y))

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            sys.exit()
    screen.fill((0, 200, 255))
    player()
    pygame.display.update()

我的 player() 函数不起作用。它没有显示任何错误,但屏幕保持空白,并且没有显示任何内容

标签: pythonpygame

解决方案


坐标 (130, 750) 位于窗口外的底部。更改 y 坐标。例如:

player_Y = 750

player_Y = 150

推荐阅读