pygamelib.gfx.core.Sprite¶
-
class
pygamelib.gfx.core.
Sprite
(sprixels=None, default_sprixel=[0m, parent=None, size=[2, 2], name=None)¶ The Sprite object represent a 2D “image” that can be used to represent any complex item. Obviously, a sprite in the pygamelib is not really an image, it is a series of glyphs (or characters) with colors (foreground and background) information.
A Sprite object is a 2D array of
Sprixel
.If you use the climage python module, you can load the generated result into a Sprite through Sprite.load_from_ansi_file().
Parameters: - sprixels (list) – A 2D array of
Sprixel
. - default_sprixel (
Sprixel
) – A default Sprixel to complete lines that are not long enough. By default, it’s an empty Sprixel. - parent (
BoardComplexItem
(suggested)) – The parent object of this Sprite. If it’s left to None, theBoardComplexItem
constructor takes ownership of the sprite. - size (list) – A 2 elements list that represent the width and height ([width, height]) of the Sprite. It is only needed if you create an empty Sprite. If you load from a file or provide an array of sprixels it’s obviously calculated automatically. Default value: [2, 2].
- name (str) – The name of sprite. If none is given, an UUID will be automatically generated.
Example:
void = Sprixel() # This represent a panda panda_sprite = Sprite( sprixels=[ [void, void, void, void, void, void, void, void], [ Sprixel.black_rect(), Sprixel.black_rect(), void, void, void, void, Sprixel.black_rect(), Sprixel.black_rect(), ], [ Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), ], [ Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.black_rect(), Sprixel.black_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.black_rect(), Sprixel.black_rect(), ], [ Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.red_rect(), Sprixel.red_rect(), Sprixel.white_rect(), Sprixel.white_rect(), ], [ void, void, Sprixel.black_rect(), Sprixel.black_rect(), Sprixel.black_rect(), Sprixel.black_rect(), void, void, ], [ void, void, Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.white_rect(), Sprixel.black_rect(), Sprixel.black_rect(), ], [ void, void, Sprixel.black_rect(), Sprixel.black_rect(), void, void, void, void, ], ], )
-
__init__
(sprixels=None, default_sprixel=[0m, parent=None, size=[2, 2], name=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([sprixels, default_sprixel, …])Initialize self. calculate_size
()Calculate the size of the sprite and update the size variable. empty
()Empty the sprite and fill it with default sprixels. flip_horizontally
()Flip the sprite horizontally. flip_vertically
()Flip the sprite vertically (i.e upside/down). from_text
(text_object)Create a Sprite from a Text
object.load_from_ansi_file
(filename[, default_sprixel])Load an ANSI encoded file into a Sprite object. set_sprixel
(row, column, val)Set a specific sprixel in the sprite to the given value. sprixel
([row, column])Return a sprixel at a specific position within the sprite. - sprixels (list) – A 2D array of