就像标题所暗示的那样,有什么区别吗?我正在使用 pygame.display.flip,我在互联网上看到,而不是使用翻转他们使用pygame.display.update.哪一个更快?
import pygame
file = 'some.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
Run Code Online (Sandbox Code Playgroud)
这输出"处理完成退出代码0",但它不播放任何内容.我该如何解决这个问题?
无法弄清楚如何在OSX Lion的virtualenv中安装PyGame.如果可能的话,我真的想保留virtualenv中包含的内容.
我已经尝试下载PyGame的源代码并运行setup.pyvirtualenv中包含的内容,但是即使在通过Homebrew安装之后,它似乎也有很多问题需要查找SDL.
有人提出的任何提示吗?
我无法想象在pygame中显示文本.
我知道我不能像常规python IDLE一样使用print但我不知道怎么做
import pygame, sys
from pygame.locals import *
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = ( 255, 0, 0)
pygame.init()
size = (700, 500)
screen = pygame.display.set_mode(size)
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('P.Earth')
while 1: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.display.update()
import time
direction = ''
print('Welcome to Earth')
pygame.draw.rect(screen, RED, [55,500,10,5], 0)
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
这只是整个计划的开始部分.
如果有一种格式允许我显示我在pygame窗口中键入的文本,那就太棒了.因此,不使用打印,我会使用其他东西.但我不知道那是什么东西:/当我在pygame中运行我的程序时,它没有显示任何东西.
我希望程序在pygame窗口中运行,而不是只在空闲时运行.
我正在尝试导入Pygame以用于我的Python版本3.3.Pygame网站上的下载只有Python 3.1和3.2.我似乎无法导入Pygame,虽然我以为我已经将它安装在正确的路径中.我已经尝试过3.1和3.2 Pygame下载.
Pygame是不是安装在正确的文件路径中,还是Pygame与我的Python版本(3.3)不兼容?
我正在运行Windows 7,这是错误:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import pygame
File ".\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pygame播放声音文件(.wav),但是当我启动它时,我从未听到任何声音.
这是代码:
import pygame
pygame.init()
pygame.mixer.init()
sounda= pygame.mixer.Sound("desert_rustle.wav")
sounda.play()
Run Code Online (Sandbox Code Playgroud)
我也试过使用频道但结果是一样的
我有以下安装pygame包的问题.
In file included from src/_numericsurfarray.c:23:
src/pygame.h:106:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^
1 error generated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
系统信息
任何建议都会非常感激?谢谢.
有没有办法在python中使用pygame模块将HSV颜色参数转换为RGB类型颜色参数?我尝试了以下代码,但它返回荒谬的值.
import colorsys
test_color = colorsys.hsv_to_rgb(359, 100, 100)
print(test_color)
Run Code Online (Sandbox Code Playgroud)
这段代码返回以下废话
(100, -9900.0, -9900.0)
Run Code Online (Sandbox Code Playgroud)
这显然不是RGB.我究竟做错了什么?
我正在尝试用Pygame和asyncio编写一个网络游戏,但我无法弄清楚如何避免挂起读取.这是我的客户代码:
@asyncio.coroutine
def handle_client():
print("Connected!")
reader, writer = yield from asyncio.open_connection('localhost', 8000)
while True:
mouse_up = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONUP:
mouse_up = True
if mouse_up:
print("Writing")
writer.write(b"Mouse up")
print("Waiting to read")
line = yield from reader.read(2**12)
print(line.decode())
writer.close()
Run Code Online (Sandbox Code Playgroud)
这就行了line = yield from reader.read(2**12).我以前认为asyncio的意思是它是非阻塞的,所以如果没有任何数据可以读取它就会继续执行.我现在看到情况并非如此.
如何将asyncio网络代码与Pygame绘图和事件代码集成?
pygame ×10
python ×9
audio ×1
colors ×1
hsv ×1
macos ×1
python-2.7 ×1
python-3.x ×1
rgb ×1
svg ×1
text ×1
virtualenv ×1
widget ×1