本文整理汇总了Python中pygame.get_error函数的典型用法代码示例。如果您正苦于以下问题:Python get_error函数的具体用法?Python get_error怎么用?Python get_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_error
def test_set_error(self):
self.assertEqual(pygame.get_error(), "")
pygame.set_error("hi")
self.assertEqual(pygame.get_error(), "hi")
pygame.set_error("")
self.assertEqual(pygame.get_error(), "")
示例2: test_get_error
def test_get_error(self):
# __doc__ (as of 2008-08-02) for pygame.base.get_error:
# pygame.get_error(): return errorstr
# get the current error message
#
# SDL maintains an internal error message. This message will usually
# be given to you when pygame.error is raised. You will rarely need to
# call this function.
#
e = pygame.get_error()
self.assertTrue(e == "" or
# This may be returned by SDL_mixer built with
# FluidSynth support. Setting environment variable
# SDL_SOUNDFONTS to the path of a valid sound font
# file removes the error message.
e == "No SoundFonts have been requested" or
e.startswith("Failed to access the SoundFont"),
e)
pygame.set_error("hi")
self.assertEqual(pygame.get_error(), "hi")
pygame.set_error("")
self.assertEqual(pygame.get_error(), "")
示例3: test_set_error
def test_set_error(self):
# The first error could be all sorts of nonsense or empty.
e = pygame.get_error()
pygame.set_error("hi")
self.assertEqual(pygame.get_error(), "hi")
pygame.set_error("")
self.assertEqual(pygame.get_error(), "")
示例4: test_set_error
def test_set_error(self):
e = pygame.get_error()
self.assertTrue(e == "" or
# This may be returned by SDL_mixer built with
# FluidSynth support. Setting environment variable
# SDL_SOUNDFONTS to the path of a valid sf2 file
# removes the error message.
e == "No SoundFonts have been requested",
e)
pygame.set_error("hi")
self.assertEqual(pygame.get_error(), "hi")
pygame.set_error("")
self.assertEqual(pygame.get_error(), "")
示例5: load_font
def load_font(f,size=30):
f = os.path.join('res', f)
try:
font = pygame.font.Font(f,size)
except pygame.error:
raise SystemExit, 'Could not load font "%s" %s'%(file, pygame.get_error())
return font
示例6: load_images_pattern
def load_images_pattern(file_pattern, scale = 1):
file_pattern = os.path.join(Globals.ART_DIR, file_pattern)
file_list = glob.glob(file_pattern)
#print file_pattern
if not file_list:
print "No file list from pattern"
return
image_list = []
for file in file_list:
#print file
try:
surface = pygame.image.load(file)
except pygame.error:
raise SystemExit, 'Could not load image "%s" %s' % (file, pygame.get_error())
if scale > 1:
surface = pygame.transform.scale(surface, (surface.get_width()*scale, surface.get_height()*scale))
img = surface.convert_alpha()
image_list.append(img)
if 0 == len(image_list):
print "Error no image list"
#print image_list
return image_list
示例7: loadImages
def loadImages(file_pattern, ObjType):
file_pattern = os.path.join(Globals.ART_DIR, file_pattern)
ObjType.file_name_list = glob.glob(file_pattern)
#print file_pattern
if not ObjType.file_name_list:
raise SystemExit, "No file list from pattern '%s'" % file_pattern
return
ObjType.image_list = []
for file in ObjType.file_name_list:
#print file
try:
surface = pygame.image.load(file)
except pygame.error:
raise SystemExit, 'Could not load image "%s" %s' % (file, pygame.get_error())
if ObjType.scale > 1:
surface = pygame.transform.scale(surface, (surface.get_width()*ObjType.scale, surface.get_height()*ObjType.scale))
img = surface.convert_alpha()
ObjType.image_list.append(img)
ObjType.num_images = len(ObjType.image_list)
if 0 == ObjType.num_images:
raise SystemExit, "Error no image list"
示例8: loadImage
def loadImage(file, alpha=True):
file = os.path.join('media', file)
try:
surface = pygame.image.load(file)
except pygame.error:
raise SystemExit, 'Could not load image "%s" %s'%(file, pygame.get_error())
return surface.convert_alpha() if alpha else surface
示例9: stop
def stop(self):
try:
pygame.mixer.music.stop()
except pygame.error:
prettyprint(COLORS.RED, 'Could not stop player! (%s)' % pygame.get_error())
raise
self.playing = False
示例10: load_image
def load_image(file):
file = os.path.join(main_dir, 'data', file)
try:
surface = pygame.image.load(file)
except pygame.error:
raise SystemExit('Could not load image "%s" %s'%(file, pygame.get_error()))
return surface
示例11: build
def build(self):
"""Called before the game loop starts."""
self.setup_cars()
self.setup_finish_line()
self.setup_event_handlers()
self.setup_hud()
# Load the background and scale to screen size.
self.background = pygame.image.load('street.png')
self.background = pygame.transform.scale(self.background,
self.scr_surf.get_size())
# Set the delay before a key starts repeating, and the repeat rate.
pygame.key.set_repeat(250, 25)
self.hud.flash("Press G to start, R to reset", 2500)
try:
self.sounds['race_start'] = pygame.mixer.Sound(file='gunshot.ogg')
self.sounds['race_end'] = pygame.mixer.Sound(file='winner.ogg')
except pygame.error:
print('Error loading sounds: {}'.format(pygame.get_error()))
exit(1)
if self.logging_enabled:
import logging
logging.info('Game done building.')
示例12: loadresources
def loadresources(self):
"""painting on the surface (once) and create sprites"""
# make an interesting background
draw_examples(self.background) # background artwork
try: # ----------- load sprite images -----------
PygView.images.append(pygame.image.load(os.path.join("data", "babytux.png"))) # index 0
# load other resources here
except:
print("pygame error:", pygame.get_error())
print("please make sure there is a subfolder 'data' and in it a file 'babytux.png'")
pygame.quit()
sys.exit()
# ------- create (pygame) Sprites Groups and Sprites -------------
self.allgroup = pygame.sprite.LayeredUpdates() # for drawing
self.ballgroup = pygame.sprite.Group() # for collision detection etc.
self.hitpointbargroup = pygame.sprite.Group()
self.bulletgroup = pygame.sprite.Group()
self.tuxgroup = pygame.sprite.Group()
self.enemygroup = pygame.sprite.Group()
# ----- assign Sprite class to sprite Groups -------
Tux.groups = self.allgroup, self.tuxgroup
Hitpointbar.groups = self.hitpointbargroup
Ball.groups = self.allgroup, self.ballgroup
Evildoge.groups = self.enemygroup, self.allgroup
Bullet.groups = self.allgroup, self.bulletgroup
self.ball1 = Ball(x=100, y=100) # creating a Ball Sprite
self.ball2 = Ball(x=200, y=100) # create another Ball Sprite
self.tux1 = Tux(x=400, y=200, dx=0, dy=0, layer=5, imagenr = 0) # over balls layer
示例13: fatalError
def fatalError(self, msg):
""" In case of critical errors, this function is called to gracefully
shut down the application and print an error message """
print(self.strings["error"])
print(msg + ": " + pygame.get_error())
pygame.quit()
sys.exit()
示例14: play_midi
def play_midi(music_file):
"""
" stream music with mixer.music module in blocking manner
" this will stream the sound from disk while playing
"""
#===== Initiate mixer =====#
freq = 44100 # audio CD quality
bitsize = -16 # unsigned 16 bit
channels = 2 # 1 is mono, 2 is stereo
buffer = 1024 # number of samples
pygame.mixer.init(freq, bitsize, channels, buffer)
pygame.mixer.music.set_volume(1.0)
clock = pygame.time.Clock()
try:
pygame.mixer.music.load(music_file)
# print "Music file %s loaded!" % music_file
except pygame.error:
print "File %s not found! (%s)" % (music_file, pygame.get_error())
return
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
# check if playback has finished
clock.tick(30)
示例15: play_sound
def play_sound(word, volume=0.8):
"""
stream music with mixer.music module in a blocking manner
this will stream the sound from disk while playing
"""
path_file = 'audio/{word}.mp3'.format(word=word)
# playsound.playsound('audio/{word}.mp3'.format(word=word), True)
# set up the mixer
freq = 44100 # audio CD quality
bitsize = -16 # unsigned 16 bit
channels = 2 # 1 is mono, 2 is stereo
buffer = 2048 # number of samples (experiment to get best sound)
pg.mixer.init(freq, bitsize, channels, buffer)
# volume value 0.0 to 1.0
pg.mixer.music.set_volume(volume)
clock = pg.time.Clock()
try:
pg.mixer.music.load(path_file)
print("Music file {} loaded!".format(path_file))
except pg.error:
print("File {} not found! ({})".format(path_file, pg.get_error()))
return
pg.mixer.music.play()
while pg.mixer.music.get_busy():
# check if playback has finished
clock.tick(30)