#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2017/04/24 12:23:25 +0900> u""" PySDL2 (pysdl2.ext) のテスト. ウインドウを表示して画像(スプライト)を表示 PySDL2 は、sdl2 と sdl2.ext の2つのパッケージで構成される。 sdl2 は、SDL2 のAPIと1:1で対応していて、 sdl2.ext は、sdl2 に比べて多少簡易な書き方ができるように sdl2 を拡張する。 今回は複雑なことはしないので、sdl2.ext だけを利用する 動作確認環境: Windows10 x64 + Python 2.7.13 32bit + PySDL2 0.9.5 Hello World — PySDL2 0.9.5 documentation http://pysdl2.readthedocs.io/en/latest/tutorial/helloworld.html """ import sdl2.ext # sdl2.ext.Resource() で、リソース(画像等)の格納場所を指定できる # 今回は res という名前のフォルダを作って、その中に画像(hello.bmp)を入れた RESOURCES = sdl2.ext.Resources(__file__, "res") # PySDL2 の初期化 sdl2.ext.init() # ウインドウを作成。タイトル文字列とウインドウサイズを指定している window = sdl2.ext.Window("Hello World", size=(640, 480)) # 作成したウインドウを表示 window.show() # スプライトを作成。hello.png を読み込んで渡す factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE) sprite = factory.from_image(RESOURCES.get_path("hello.png")) # スプライトの表示位置を指定 sprite.position = 24, 24 # スプライトを描画 spriterenderer = factory.create_sprite_render_system(window) spriterenderer.render(sprite) # イベントループ。閉じるボタンが押されるまで待つ(ループする) processor = sdl2.ext.TestEventProcessor() processor.run(window) # 終了処理。今まで確保したアレコレを破棄する sdl2.ext.quit()