为什么在pygame中,我的显示器会拖到屏幕后面



所以我正在学习pygame,我想为精灵使用像素艺术,我正在尝试放大我的显示器,但它似乎绘制在主显示器后面,而不是前面

import sys, math
import pygame
from pygame.locals import *
pygame.init()

fps = 60
is_running = True
clock = pygame.time.Clock()
window_size = [600, 400]
scale_size = [300, 200]

screen = pygame.display.set_mode(window_size)
display = pygame.Surface(scale_size)

player_img = pygame.image.load("images/player.png")
player_pos = [150, 100]
player_move_speed = 3
player_y_momentum = 1

while is_running:
for event in pygame.event.get():        
if event.type == QUIT:
is_running = False
pygame.quit()
sys.exit()

surf = pygame.transform.scale(display, window_size)
screen.blit(surf, (0, 0))

surf.blit(player_img, player_pos)
surf.fill((255, 255, 255))

pygame.display.update()
clock.tick(fps)

我试着解决这个问题,但似乎找不到的解决方案

绘图/填充的顺序很重要!


将顺序更改为以下内容:

while is_running:
for event in pygame.event.get():
if event.type == QUIT:
is_running = False
pygame.quit()
sys.exit()
surf = pygame.transform.scale(display, window_size)
surf.fill((255, 255, 255))
surf.blit(player_img, player_pos)
screen.blit(surf, (0, 0))
pygame.display.update()
clock.tick(fps)

相关内容

  • 没有找到相关文章

最新更新