本文介绍了Pygame 无响应显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试使用精灵为具有 X 和 Y 移动的基本 2D Python 游戏创建基础.

然而,尽管这里的代码尝试 screen.fillscreen.blit

,但显示没有响应

playerX = 50玩家Y = 50player = pygame.image.load("player.png")宽、高 = 64*8、64*8屏幕=pygame.display.set_mode((宽度,高度))screen.fill((255,255,255))screen.blit(player, (playerX, playerY))

我是否遗漏了一些重要的东西?

解决方案

一个最小的、典型的 PyGame 应用程序

  • 有一个游戏循环

  • 必须通过

    导入pygamepygame.init()玩家X = 50玩家Y = 50player = pygame.image.load("player.png")宽、高 = 64*8、64*8screen = pygame.display.set_mode((width, height))# 主应用程序循环运行 = 真运行时:# 事件循环对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:运行 = 错误# 清除显示screen.fill((255,255,255))# 绘制场景screen.blit(player, (playerX, playerY))# 更新显示pygame.display.flip()

    So I am attempting to create the foundation for a basic 2D python game with X and Y movement using a sprite.

    However the display is unresposive despite the code here attempting to screen.fill and screen.blit

    playerX = 50
    playerY = 50
    player = pygame.image.load("player.png")
    width, height = 64*8, 64*8
    screen=pygame.display.set_mode((width, height))
    screen.fill((255,255,255))
    screen.blit(player, (playerX, playerY))
    

    Am I missing something important?

    解决方案

    A minimal, typical PyGame application

    See pygame.event.get():

    See also Python Pygame Introduction

    Minimal example:

    import pygame
    
    pygame.init()
    
    playerX = 50
    playerY = 50
    player = pygame.image.load("player.png")
    width, height = 64*8, 64*8
    screen = pygame.display.set_mode((width, height))
    
    # main application loop
    run = True
    while run:
    
        # event loop
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
    
        # clear the display
        screen.fill((255,255,255))
    
        # draw the scene
        screen.blit(player, (playerX, playerY))
    
        # update the display
        pygame.display.flip()
    

    这篇关于Pygame 无响应显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 05:54