Texture Management

arcade.Texture

class arcade.Texture(name: str, image: Optional[PIL.Image.Image] = None, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5)[source]

Class that represents a texture. Usually created by the load_texture or load_textures commands.

Parameters
  • name (str) – Name of texture. Used for caching, so must be unique for each texture.

  • image (PIL.Image.Image) – Image to use as a texture.

  • hit_box_algorithm (str) –

    One of None, ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the PhysicsEngineSimple, PhysicsEnginePlatformer and ‘Detailed’ for the PymunkPhysicsEngine.

    ../_images/hit_box_algorithm_none.png

    hit_box_algorithm = “None”

    ../_images/hit_box_algorithm_simple.png

    hit_box_algorithm = “Simple”

    ../_images/hit_box_algorithm_detailed.png

    hit_box_algorithm = “Detailed”

  • hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box

Attributes:
name

Unique name of the texture. Used by load_textures for caching. If you are manually creating a texture, you can just set this to whatever.

image

A PIL.Image.Image object.

width

Width of the texture in pixels.

height

Height of the texture in pixels.

classmethod create_empty(name: str, size: Tuple[int, int]) arcade.texture.Texture[source]

Create an empty texture with a black image.

This can be used to allocate space in texture atlases. The hit box algorithm will be a simply bounding box (None) since we have no pixel data to possibly determine a hit box.

Note that this creates an internal empty RGBA Pillow Image. If creating many large textures be aware of the memory usage (4 bytes per pixel). Optionally the normal texture initializer can be used providing your own image. If making many equally sized empty texture the same image an be reused across across these textures.

The internal image can also be latered with Pillow draw commands and written/updated to a texture atlas. This works great for infrequent changes. For frequent texture changes you should instead render directly into the texture atlas.

Parameters
  • name (str) – The unique name for this texture

  • size (Tuple[int,int]) – The xy size of the internal image.

draw_scaled(center_x: float, center_y: float, scale: float = 1.0, angle: float = 0, alpha: int = 255)[source]

Draw the texture.

Parameters
  • center_x (float) – X location of where to draw the texture.

  • center_y (float) – Y location of where to draw the texture.

  • scale (float) – Scale to draw rectangle. Defaults to 1.

  • angle (float) – Angle to rotate the texture by.

  • alpha (int) – The transparency of the texture (0-255).

property height: int

Height of the texture in pixels.

property size: Tuple[int, int]

Width and height as a tuple

property width: int

Width of the texture in pixels.

arcade.cleanup_texture_cache

arcade.cleanup_texture_cache()[source]

This cleans up the cache of textures. Useful when running unit tests so that the next test starts clean.

arcade.load_spritesheet

arcade.load_spritesheet(file_name: Union[str, pathlib.Path], sprite_width: int, sprite_height: int, columns: int, count: int, margin: int = 0) List[arcade.texture.Texture][source]
Parameters
  • file_name (str) – Name of the file to that holds the texture.

  • sprite_width (int) – Width of the sprites in pixels

  • sprite_height (int) – Height of the sprites in pixels

  • columns (int) – Number of tiles wide the image is.

  • count (int) – Number of tiles in the image.

  • margin (int) – Margin between images

Returns List

List of Texture objects.

arcade.load_texture

arcade.load_texture(file_name: Union[str, pathlib.Path], x: float = 0, y: float = 0, width: float = 0, height: float = 0, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, can_cache: bool = True, mirrored: Optional[bool] = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5) arcade.texture.Texture[source]

Load an image from disk and create a texture.

Note: If the code is to load only part of the image, the given x, y coordinates will start with the origin (0, 0) in the upper left of the image. When drawing, Arcade uses (0, 0) in the lower left corner. Be careful with this reversal.

For a longer explanation of why computers sometimes start in the upper left, see: http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

Parameters
  • file_name (str) – Name of the file to that holds the texture.

  • x (float) – X position of the crop area of the texture.

  • y (float) – Y position of the crop area of the texture.

  • width (float) – Width of the crop area of the texture.

  • height (float) – Height of the crop area of the texture.

  • flipped_horizontally (bool) – Mirror the sprite image. Flip left/right across vertical axis.

  • flipped_vertically (bool) – Flip the image up/down across the horizontal axis.

  • flipped_diagonally (bool) – Transpose the image, flip it across the diagonal.

  • can_cache (bool) – If a texture has already been loaded, load_texture will return the same texture in order to save time. Sometimes this is not desirable, as resizing a cached texture will cause all other textures to resize with it. Setting can_cache to false will prevent this issue at the experience of additional resources.

  • mirrored (bool) – Deprecated.

  • hit_box_algorithm (str) –

    One of ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the PhysicsEngineSimple, PhysicsEnginePlatformer and ‘Detailed’ for the PymunkPhysicsEngine.

    ../_images/hit_box_algorithm_none.png

    hit_box_algorithm = “None”

    ../_images/hit_box_algorithm_simple.png

    hit_box_algorithm = “Simple”

    ../_images/hit_box_algorithm_detailed.png

    hit_box_algorithm = “Detailed”

  • hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box

Returns

New Texture object.

Raises

ValueError

arcade.load_texture_pair

arcade.load_texture_pair(filename, hit_box_algorithm: str = 'Simple')[source]

Load a texture pair, with the second being a mirror image of the first. Useful when doing animations and the character can face left/right.

arcade.load_textures

arcade.load_textures(file_name: Union[str, pathlib.Path], image_location_list: Union[Tuple[Union[Tuple[float, float, float, float], List[float]], ...], List[Union[Tuple[float, float, float, float], List[float]]]], mirrored: bool = False, flipped: bool = False) List[arcade.texture.Texture][source]

Load a set of textures from a single image file.

Note: If the code is to load only part of the image, the given x, y coordinates will start with the origin (0, 0) in the upper left of the image. When drawing, Arcade uses (0, 0) in the lower left corner. Be careful with this reversal.

For a longer explanation of why computers sometimes start in the upper left, see: http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

Parameters
  • file_name (str) – Name of the file.

  • image_location_list (List) – List of image sub-locations. Each rectangle should be a List of four floats: [x, y, width, height].

  • mirrored (bool) – If set to True, the image is mirrored left to right.

  • flipped (bool) – If set to True, the image is flipped upside down.

Returns

List of Texture’s.

Raises

ValueError

arcade.make_circle_texture

arcade.make_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], name: Optional[str] = None) arcade.texture.Texture[source]

Return a Texture of a circle with the given diameter and color.

Parameters
  • diameter (int) – Diameter of the circle and dimensions of the square Texture returned.

  • color (Color) – Color of the circle.

  • name (str) – Custom or pre-chosen name for this texture

Returns

New Texture object.

arcade.make_soft_circle_texture

arcade.make_soft_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0, name: Optional[str] = None) arcade.texture.Texture[source]

Return a Texture of a circle with the given diameter and color, fading out at its edges.

Parameters
  • diameter (int) – Diameter of the circle and dimensions of the square Texture returned.

  • color (Color) – Color of the circle.

  • center_alpha (int) – Alpha value of the circle at its center.

  • outer_alpha (int) – Alpha value of the circle at its edges.

  • name (str) – Custom or pre-chosen name for this texture

Returns

New Texture object.

Return type

arcade.Texture

arcade.make_soft_square_texture

arcade.make_soft_square_texture(size: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0, name: Optional[str] = None) arcade.texture.Texture[source]

Return a Texture of a square with the given diameter and color, fading out at its edges.

Parameters
  • size (int) – Diameter of the square and dimensions of the square Texture returned.

  • color (Color) – Color of the square.

  • center_alpha (int) – Alpha value of the square at its center.

  • outer_alpha (int) – Alpha value of the square at its edges.

  • name (str) – Custom or pre-chosen name for this texture

Returns

New Texture object.

arcade.trim_image

arcade.trim_image(image: PIL.Image.Image) PIL.Image.Image[source]

Crops the extra whitespace out of an image.

Returns

New PIL.Image.Image object.