微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pygame开始运行时出现错误

如何解决pygame开始运行时出现错误

运行时控制台出现错误



--> python3 -m poetry init --no-interaction --name repl_python3_SycoBaksGame

This command will guide you through creating your pyproject.toml config.


You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests ^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - An url (https://example.com/packages/my-package-0.1.0.tar.gz)



pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
xcb_connection_has_error() returned true
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
xcb_connection_has_error() returned true
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) UnkNown PCM default
 

我的代码

import pygame

#Canvas Creation

pygame.init()

win = pygame.display.set_mode((500,500))
pygame.display.set_caption("SycoBaks Game")

#Position
x = 250
y = 250

#Size
width = 20
height = 20

#VeLocity/Time
speed = 5


#SycoBak Main GameFrame

run = True

while not run:
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
            
    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
      x=x-1
    
    if keys[pygame.K_RIGHT]:
      x=x+1
    
    if keys[pygame.K_UP]:
      y=y-1

    if keys[pygame.K_DOWN]:
      y=y+1



    pygame.draw.rect(win,(255,0),(x,y,width,height))

    pygame.display.update()

pygame.quit()

如果有什么可以帮助我解决错误代码,因为我认为自己的代码没有问题,那将是一个pygame依赖问题,但我不知道 *

解决方法

pygame.init()做的是尝试为您shown here初始化所有的pygame模块

我认为这是在导入需要一些工作(不需要)的模块,并强迫您执行一些不需要的代码。尝试导入您需要的模块。 您可以init()所需的每个模块。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。