def run(): video.init () freetype.init (8) font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf")) screen = video.set_mode (800, 600) screen.fill (colors["grey_light"]) sf, w, h = font.render("Hello World", colors["red"], colors['grey_dark'], ptsize=64, style=ftconstants.STYLE_UNDERLINE|ftconstants.STYLE_ITALIC) screen.blit (sf, (32, 32)) font.render("abcdefghijklm", colors["grey_dark"], colors["green"], ptsize=64, dest=(screen, 32, 128)) font.vertical = True font.render("Vertical?", colors["blue"], ptsize=32, dest=(screen, 32, 190)) font.vertical = False font.render("Let's spin!", colors["red"], ptsize=48, rotation=55, dest=(screen, 64, 190)) font.render("All around!", colors["green"], ptsize=48, rotation=-55, dest=(screen, 150, 270)) font.render("and BLEND", pygame2.Color(255, 0, 0, 128), ptsize=64, dest=(screen, 250, 220)) font.render("or BLAND!", pygame2.Color(0, 0xCC, 28, 128), ptsize=64, dest=(screen, 258, 237)) text = "I \u2665 Unicode" if sys.version_info[0] < 3: text = "I " + unichr(0x2665) + " Unicode" font.render(text, pygame2.Color(0, 0xCC, 0xDD), ptsize=64, dest=(screen, 298, 320)) text = "\u2665" if sys.version_info[0] < 3: text = unichr(0x2665) font.render(text, colors["grey_light"], colors["red"], ptsize=148, dest=(screen, 480, 32)) font.render("...yes, this is a SDL surface", pygame2.Color(0, 0, 0), ptsize=24, style=ftconstants.STYLE_BOLD, dest=(screen, 380, 380)) screen.flip () okay = True while okay: for ev in event.get (): if ev.type == constants.QUIT: okay = False if ev.type == constants.KEYDOWN and ev.key == constants.K_ESCAPE: okay = False video.quit ()
def run (): video.init () freetype.init () font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf")) fpsmanager = sdlgfx.FPSmanager (2) screen = video.set_mode (640, 480) wm.set_caption ("FPSmanager example") screenrect = pygame2.Rect (640, 480) screen.fill (black) screen.flip () okay = True while okay: for ev in event.get (): if ev.type == sdlconst.QUIT: okay = False if ev.type == sdlconst.KEYDOWN: framerate = fpsmanager.framerate if ev.key == sdlconst.K_ESCAPE: okay = False elif ev.key in (sdlconst.K_PLUS, sdlconst.K_KP_PLUS): framerate = min (framerate + 1, gfxconst.FPS_UPPER_LIMIT) fpsmanager.framerate = framerate elif ev.key in (sdlconst.K_MINUS, sdlconst.K_KP_MINUS): framerate = max (framerate - 1, gfxconst.FPS_LOWER_LIMIT) fpsmanager.framerate = framerate screen.fill (black) prev = time.time () fpsmanager.delay () last = time.time () millis = ((last - prev) * 1000) fpstext = "FPS: %d" % fpsmanager.framerate timetext = "time (ms) passed since last update: %.3f" % millis surfacef, w, h = font.render (fpstext, white, ptsize=28) surfacet, w2, h2 = font.render (timetext, white, ptsize=28) blitrect = pygame2.Rect (w, h) blitrect.center = screenrect.centerx, screenrect.centery - h screen.blit (surfacef, blitrect.topleft) blitrect = pygame2.Rect (w2, h2) blitrect.center = screenrect.centerx, screenrect.centery + h screen.blit (surfacet, blitrect.topleft) screen.flip () video.quit ()
def run (): freetype.init () video.init () sdlmixer.init () sdlmixer.open_audio (sdlmixerconst.DEFAULT_FREQUENCY, sdlmixerconst.DEFAULT_FORMAT, sdlmixerconst.DEFAULT_CHANNELS, 1024) print ("Detected decoders: %s" % sdlmixer.get_decoders ()) sound = sdlmixer.Chunk (pygame2.examples.RESOURCES.get ("house_lo.wav")) channel_sound = sdlmixer.Channel (1) font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf")) surfaces = get_help (font) screen = video.set_mode (640, 480) wm.set_caption ("SDL_mixer sound example") screenrect = pygame2.Rect (640, 480) screen.fill (black) yoff = 100 for (sf, w, h) in surfaces: screen.blit (sf, (100, yoff)) yoff += h + 10 screen.flip () okay = True while okay: for ev in event.get (): if ev.type == sdlconst.QUIT: okay = False if ev.type == sdlconst.KEYDOWN: # play, pause, resume if ev.key == sdlconst.K_SPACE: if channel_sound.paused: print ("Resuming") channel_sound.resume () elif channel_sound.playing: print ("Pausing") channel_sound.pause () else: print ("Starting") channel_sound.play (sound, -1) if ev.key == sdlconst.K_ESCAPE: # exit the application okay = False elif ev.key in (sdlconst.K_PLUS, sdlconst.K_KP_PLUS): # increase volume channel_sound.volume = min (channel_sound.volume + 1, sdlmixerconst.MAX_VOLUME) print ("Volume is now: %d" % channel_sound.volume) elif ev.key in (sdlconst.K_MINUS, sdlconst.K_KP_MINUS): # decrease volume channel_sound.volume = max (channel_sound.volume - 1, 0) print ("Volume is now: %d" % channel_sound.volume) screen.flip () freetype.quit () video.quit () sdlmixer.close_audio () sdlmixer.quit ()
def setUp (self): ft.init () pygame2.sdl.video.init()