メニュー

pygame

pygameのトップレベルパッケージ

このpygameパッケージは他のパッケージを使用するためのトップレベルパッケージです。 Pygame自体は多くのサブモジュールに分割されていますが、 そのことはPygameを使ってプログラムをするうえで特に影響はありません。

Pygameで使用されるトップレベル変数は、見つけやすいように殆どが'pygame.locals'という名前のモジュール内で定義されています。これらの変数は、プログラムの先頭に'import pygame'のimport文を記述するのに加え、'from pygame.locals import *'のimport文も記述することで使用できるようになります。

'import pygame'でpygameモジュールをインポートした時には、使用できる全てのpygameサブモジュールも自動的にインポートされます。pygameモジュールのいくつかは"オプション"と見なされて、使用できない場合があるので注意してください。その場合、 Pygame will provide a placeholder object instead of the module, which can be used to test for availability.

the top level pygame package

The pygame package represents the top-level package for others to use. Pygame itself is broken into many submodules, but this does not affect programs that use Pygame.

As a convenience, most of the top-level variables in pygame have been placed inside a module named 'pygame.locals'. This is meant to be used with 'from pygame.locals import *', in addition to 'import pygame'.

When you 'import pygame' all available pygame submodules are automatically imported. Be aware that some of the pygame modules are considered "optional", and may not be available. In that case, Pygame will provide a placeholder object instead of the module, which can be used to test for availability.


pygame.init

インポートした全てのpygameモジュールを初期化します。
pygame.init(): return (初期化成功したモジュールの数, 初期化に失敗したモジュールの数)

インポートした全てのpygameモジュールを初期化します。モジュールの初期化に失敗しても例外は発生しませんが、初期化に 成功したモジュールの数と失敗したモジュールの数がタプル型の戻り値として返されます。個々のモジュールを手動で初期化することもできますが、pygame.initでまとめて行った方が手っ取り早いです。個々のモジュールを手動で初期化した場合、失敗すると例外が発生してしまいます。

プログラムを高速化するため、またゲームで使用しないモジュールは読み込まないよう、モジュールを別々に初期化することもできます。

二回以上 init() を実行しても問題ありません: 複数回実行して特に影響はありません。全ての pygame モジュールの初期化を解除するpygame.quitを実行した後でも同様です。

initialize all imported pygame modules.
pygame.init(): return (numpass, numfail)

Initialize all imported Pygame modules. No exceptions will be raised if a module fails, but the total number if successful and failed inits will be returned as a tuple. You can always initialize individual modules manually, but pygame.init is a convenient way to get everything started. The init() functions for individual modules will raise exceptions when they fail.

You may want to initalise the different modules seperately to speed up your program or to not use things your game does not.

It is safe to call this init() more than once: repeated calls will have no effect. This is true even if you have pygame.quit - uninitialize all pygame modules all the modules.


pygame.quit

全てのpygameモジュールの初期化を解除します。
pygame.quit(): return None

既に初期化されている全てのpygameモジュールの初期化を解除します。Python インタープリタが終了する時には勝手にこの命令が実行されるので、 プログラム中で特に実行する必要はありません。pygameが使用しているリソースを一旦開放したうえでプログラムを続ける場合に使用します。二回以上 quit() を実行しても問題ありません:複数回実行して特に影響はありません。

注意していただきたいのですが pygame.quit はプログラムを終了させる命令ではありません。プログラムを終了する時には普通のPythonプログラムと同じように終了処理を行ってください。

uninitialize all pygame modules.
pygame.quit(): return None

Uninitialize all pygame modules that have previously been initialized. When the Python interpreter shuts down, this method is called regardless, so your program should not need it, except when it wants to terminate its pygame resources and continue. It is safe to call this function more than once: repeated calls have no effect.

Note, that pygame.quit will not exit your program. Consider letting your program end in the same way a normal python program will end.


pygame.error

標準のpygameの例外です。
pygame.errorメッセージを発生させます。

この例外はpygameもしくはSDLの操作が失敗した場合に発生します。エラー内容から発生している問題を予測し、エラーに対処することができます。例外が発生する時にはその問題に関する詳細なメッセージも得られます。

Derived from the RuntimeError exception, which can also be used to catch these raised errors.

standard pygame exception.
raise pygame.error, message.

This exception is raised whenever a pygame or SDL operation fails. You can catch any anticipated problems and deal with the error. The exception is always raised with a descriptive message about the problem.

Derived from the RuntimeError exception, which can also be used to catch these raised errors.


pygame.get_error

最新エラーメッセージを取得します。
pygame.get_error(): return エラーメッセージ

SDL は内部エラーメッセージを保持します。保持されたメッセージは、通常pygame.errorが発生した時にあなたへ伝えられます。 この機能を使用することはあまりないかもしれません。

get the current error message.
pygame.get_error(): return errorstr.

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.


pygame.set_error

最新エラーメッセージをセットします。
pygame.set_error(error_msg): return None

SDL は内部エラーメッセージを保持します。保持されたメッセージは、通常pygame.errorが発生した時にあなたへ伝えられます。 この機能を使用することはあまりないかもしれません。

set the current error message.
pygame.set_error(error_msg): return None

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.


pygame.get_sdl_version

SDLのバージョンを取得します。
pygame.get_sdl_version(): return (メジャーバージョン情報, マイナーバージョン情報, パッチ情報)

SDLの三つのバージョンナンバーを戻り値として返します。このバージョン情報はSDLのコンパイル時に設定されたものです。これによりpygameの関数を使用できるか調べることができます。

この機能 はpygame1.7.0 で新しく追加されたものです

get the version number of SDL.
pygame.get_sdl_version(): return major, minor, patch

Returns the three version numbers of the SDL library. This version is built at compile time. It can be used to detect which features may not be available through Pygame.

get_sdl_version is new in pygame 1.7.0


pygame.get_sdl_byteorder

SDLのバイトオーダーを取得します。
pygame.get_sdl_byteorder(): return int

SDLのバイトオーダーを戻り値として返します。バイトオーダーがリトルエンディアンの時は LIL_ENDIAN(1234と定義された定数)を返し、ビッグエンディアンの場合は BIG_ENDIAN(4321と定義された定数) を返します。

この機能 はpygame1.8 で新しく追加されたものです

get the byte order of SDL.
pygame.get_sdl_byteorder(): return int

Returns the byte order of the SDL library. It returns LIL_ENDIAN for little endian byte order and BIG_ENDIAN for big endian byte order.

get_sdl_byteorder is new in pygame 1.8


pygame.register_quit

pygameを終了する時に実行する関数を登録します。
register_quit(callable): return None

pygame.quit関数が実行された時、登録された全ての関数も同時に実行されます。この関数はPygameモジュールを初期化した時に自動的に実行されます。普通のpygameユーザーであればこれを実行する必要はありません。

register a function to be called when pygame quits.
register_quit(callable): return None

When pygame.quit is called, all registered quit functions are called. Pygame modules do this automatically when they are initializing. This function is not be needed for regular pygame users.


pygame.version

pygameのバージョン情報を保持しているモジュールです。
module pygame.version

このモジュールは自動的にpygameパッケージ内に取り込まれ、pygameのバージョンを確認するための二つの変数が使用可能になります。

module containing version information.
module pygame.version

This module is automatically imported into the pygame package and offers a few variables to check with version of pygame has been imported.


pygame.version.ver

文字列としてバージョン情報。
pygame.version.ver = '1.2'

これは文字列として表わされるバージョン情報です。例えば、'1.5.2'といった細かいリリース情報を保持することができます。

pygame.version.ver
pygame.version.ver = '1.2'

This is the version represented as a string. It can contain a micro release number as well, e.g., '1.5.2'


pygame.version.vernum

タプル型数値としてのバージョン情報。
pygame.version.vernum = (1, 5, 3)

pygame.version.vernumで取得されたバージョン情報同士であれば、バージョン情報の比較を簡単に行うことができます。Pygameのバージョン情報をチェックする方法は、以下のようになります。:

    if pygame.version.vernum < (1, 5):
        print 'Warning, older version of Pygame (%s)' %  pygame.version.ver
        disable_advanced_features = True
tupled integers of the version
pygame.version.vernum = (1, 5, 3)

This variable for the version can easily be compared with other version numbers of the same format. An example of checking Pygame version numbers would look like this:

    if pygame.version.vernum < (1, 5):
        print 'Warning, older version of Pygame (%s)' %  pygame.version.ver
        disable_advanced_features = True