这是你在游戏中可以做的最简单的代码。它所做的就是创建一个窗口并允许您关闭它。然而,我得到的错误pygame.error:视频系统没有初始化。我在网上搜索了这个,似乎大多数人都忘记打电话给pygame.init()了。我不知道为什么我会犯这个错误。
import pygame
pygame.init()
screen = pygame.display.set_mode((900,500))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygam
我刚开始玩游戏,我正试着为我的游戏做一个菜单。现在,我想要两个不同的屏幕,一个将显示在菜单中,另一个将显示在游戏的“自定义”部分。我尝试创建一个主循环和两个内部循环,它们只在它们应该运行的时候运行。
目前,菜单和自定义之间的转换被认为是按"d“键完成的。从菜单到自定义的过渡菜单完成得很完美,但是到菜单的转换却在破坏游戏。
这是主循环:
while running:
while menu:
pygame.display.flip()
screen.blit(bg, (0, 0))
for event in pygame.event.
为什么pygame.event.get()会给出这个错误?
错误:视频系统未初始化
代码是功能性的,但在执行函数后会出现此错误。
pygame.event.get()
while not pygame.mouse.get_pressed()[0]:
key = pygame.key.get_pressed()
if key[pygame.K_SPACE]:
pygame.quit()
pygame.event.get()
程序退出,但给出了上述错误。
我的程序不仅使用Pygame,而且还使用Tkinter,所以我有一个tkinter窗口运行,而pygame窗口正在运行。通常的做法是,在common代码中执行sys.exit()以停止pygame.error: video system not initialized错误,以下面的代码片段为例。这方面的问题是,如果您不只是在运行游戏代码,这个“解决方案”将停止代码中的所有内容,而不是仅仅停止吡咯窗口。(FYI,这个错误并没有使程序崩溃或停止,所以它只是一个控制台的事情,但它仍然是恼人的)。
import pygame, sys
while True: # event loop
目前,我正在尝试为学校作业创建一个游戏,在我的某个级别上为某些事件设置计时器,但是"UnboundLocalError“不断出现,我不知道如何修复它。我读过一些其他的文章,您可以将变量设置为全局变量,但是我尝试过一些地方,但它仍然给了我同样的错误。我们使用python 3.4.3。
这是我的代码:
import pygame
import random
import sys
import time
import os
#Global Colours and Variables
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 25
我刚刚开始了一个小游戏项目,我试图让它在每次子弹发射时都会播放声音,但我总是得到相同的错误:
pygame.error: mixer system not initialized
我不知道我做错了什么,所以下面是我的代码:
import pygame, sys
from pygame.locals import *
theClock = pygame.time.Clock()
sound = pygame.mixer.Sound("bullet.mp3")
……
if event.type == KEYDOWN:
if event.key == K_SPACE an
import pygame
pygame.init()
screen = pygame.display.set_mode((800,600))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.quit():
running = False
这里的代码是具有窗口大小、主游戏循环和事件循环的基本游戏代码。
当我运行这段代码时,游戏窗口会立即打开并关闭。它给了我这个错误:
video system has not initi
运行这段代码后,我得到了一个错误:
pygame.error: video system not initialized
我的代码:
import sys
import pygame
def run_game():
# Initialize game and create a screen object.
pygame.init()
screen = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alien Invasion")
# Start the main
当我尝试加载我的游戏时,除了崩溃和python没有响应这一事实外,一切都能工作。我看不见我错过了什么。
以下是整个代码:
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
import pygame
import random
from os import path
img_dir = path
我正在使用游戏的操纵杆api与我的项目在无头系统上使用操纵杆,但游戏需要一个“屏幕”,所以我已经设置了一个虚拟视频系统来克服这一点。它工作得很好,但现在它突然给了我这个错误:
Traceback (most recent call last):
File "compact.py", line 10, in <module>
screen = display.set_mode((1, 1))
pygame.error: Unable to open a console terminal
这里是我作为无头设置,应该克服这个问题。
from pygame im
当我尝试运行我的电子游戏代码pygame.error时,我得到了这个错误:视频系统没有初始化。我正在使用Repl.it,并试图创建一个瞄准游戏,它可以跟踪精度,在其中你只有3个生命。 import pygame
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False # Here we exit the Loop and execute what after
pygame.quit()
# Play Su
每当我试图执行我的pygame代码:pygame.error: video system not initialized时,我都会收到这个错误。
from sys import exit
import pygame
from pygame.locals import *
black = 0, 0, 0
white = 255, 255, 255
red = 255, 0, 0
green = 0, 255, 0
blue = 0, 0, 255
screen = screen_width, screen_height = 600, 400
clock = pygame.time.Cloc
我试着用Pygame检测到一个USB游戏。每次我运行这段代码时,程序都会出现错误:第10行中的“program未初始化”。
import pygame as p
p.init()
stick = p.joystick.Joystick(0)
#get init returns always False
print("initialized:",bool(stick.get_init()))
#getting the name works as it should
print(stick.get_name())
#says always "pygame.error: J
这是我的密码:
import pygame, sys
from pygame.locals import *
pygame.init()
#set up window
DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32)
#set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
#draw on the surface object
DISPLAYSURF.fi
我正在尝试做一个模拟,它需要用户输入3个参数。我需要的输入是显示的X和Y维度以及迭代次数。
def max_rows():
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_RETURN: