pygame.init

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.localspygame constants 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()
initialize all imported pygame modules
init() -> (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()initialize all imported pygame modules 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() all the modules.




pygame.quit()
uninitialize all pygame modules
quit() -> 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()uninitialize all pygame modules will not exit your program. Consider letting your program end in the same way a normal python program will end.




exception pygame.error
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()
get the current error message
get_error() -> errorstr
SDL maintains an internal error message. This message will usually be given to you when pygame.error()standard pygame exception is raised. You will rarely need to call this function.




pygame.set_error()
set the current error message
set_error(error_msg) -> None
SDL maintains an internal error message. This message will usually be given to you when pygame.error()standard pygame exception is raised. You will rarely need to call this function.




pygame.get_sdl_version()
get the version number of SDL
get_sdl_version() -> 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()
get the byte order of SDL
get_sdl_byteorder() -> 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()
register a function to be called when pygame quits
register_quit(callable) -> None
When pygame.quit()uninitialize all pygame modules 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.encode_string()
Encode a unicode or bytes object
encode_string([obj [, encoding [, errors [, etype]]]]) -> bytes or None
obj: If unicode, encode; if bytes, return unaltered; if anything else, return None; if not given, raise SyntaxError.


encoding (string): If present, encoding to use. The default is ‘unicode_escape’.


errors (string): If given, how to handle unencodable characters. The default is ‘backslashreplace’.


etype (exception type): If given, the exception type to raise for an encoding error. The default is UnicodeEncodeError, as returned by PyUnicode_AsEncodedString(). For the default encoding and errors values there should be no encoding errors.


This function is used in encoding file paths. Keyword arguments are supported.


Added in Pygame 1.9.2 (primarily for use in unit tests)




pygame.encode_file_path()
Encode a unicode or bytes object as a file system path
encode_file_path([obj [, etype]]) -> bytes or None
obj: If unicode, encode; if bytes, return unaltered; if anything else, return None; if not given, raise SyntaxError.


etype (exception type): If given, the exception type to raise for an encoding error. The default is UnicodeEncodeError, as returned by PyUnicode_AsEncodedString().


This function is used to encode file paths in Pygame. Encoding is to the codec as returned by sys.getfilesystemencoding(). Keyword arguments are supported.


Added in Pygame 1.9.2 (primarily for use in unit tests)




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值