CLASS v1.8.0

Texture

pykraken.Texture

Represents a hardware-accelerated image that can be efficiently rendered.

More about Texture

Textures store shared image data loaded from image files or pixel arrays. Source regions, tint, alpha, flips, and blend modes belong to renderer draw calls, so the same texture can be reused by sprites with independent appearances.

Reference

PYTHON API

Constructor

method3 overloads
Texture(file_path: str | PathLike, filter: FilterMode = FilterMode.DEFAULT, access: TextureAccess = TextureAccess.STATIC, usage: TextureUsage = TextureUsage.DRAWABLE)
Texture(pixel_array: PixelArray, filter: FilterMode = FilterMode.DEFAULT, access: TextureAccess = TextureAccess.STATIC, usage: TextureUsage = TextureUsage.DRAWABLE)
Texture(width: int, height: int, filter: FilterMode = FilterMode.DEFAULT, usage: TextureUsage = TextureUsage.DRAWABLE)

Overloaded function.

  1. Texture(file_path: str | PathLike, filter: FilterMode = FilterMode.DEFAULT, access: TextureAccess = TextureAccess.STATIC, usage: TextureUsage = TextureUsage.DRAWABLE)

Create a Texture by loading an image from a file. If no scale mode is provided, the default renderer scale mode is used.

Args

  • file_path (str | PathLike[str]) — Path to the image file to load.
  • filter (FilterMode, optional) — Scaling/filtering mode for the texture.
  • access (TextureAccess, optional) — Texture access type (STATIC or TARGET).
  • usage (TextureUsage, optional) — Texture usage flags controlling renderer and GPU access.

Raises

  • ValueError — If file_path is empty.
  • RuntimeError — If the file cannot be loaded or texture creation fails.
  1. Texture(pixel_array: PixelArray, filter: FilterMode = FilterMode.DEFAULT, access: TextureAccess = TextureAccess.STATIC, usage: TextureUsage = TextureUsage.DRAWABLE)

Create a Texture from an existing PixelArray. If no scale mode is provided, the default renderer scale mode is used.

Args

  • pixel_array (PixelArray) — The pixel array to convert to a texture.
  • filter (FilterMode, optional) — Scaling/filtering mode for the texture.
  • access (TextureAccess, optional) — Texture access type (STATIC or TARGET).
  • usage (TextureUsage, optional) — Texture usage flags controlling renderer and GPU access.

Raises

  • RuntimeError — If texture creation from pixel array fails.
  1. Texture(width: int, height: int, filter: FilterMode = FilterMode.DEFAULT, usage: TextureUsage = TextureUsage.DRAWABLE)

Create a (render target) Texture with the specified size. If no scale mode is provided, the default renderer scale mode is used.

Args

  • width (int) — The width of the texture in pixels (must be > 0).
  • height (int) — The height of the texture in pixels (must be > 0).
  • filter (FilterMode, optional) — Scaling/filtering mode for the texture.
  • usage (TextureUsage, optional) — Texture usage flags controlling renderer and GPU access.

Raises

  • RuntimeError — If texture creation fails.

height

property
height: int

The height of the texture in pixels.

size

property
size: Vec2

The dimensions of the texture as a Vec2.

usage

property
usage: TextureUsage

The usage flags describing how the texture can be used.

Returns

  • TextureUsage — The texture usage bitmask.

width

property
width: int

The width of the texture in pixels.

get_rect

method
get_rect(self) -> Rect

Return a Rect with position (0, 0) and the texture's dimensions.

Returns

  • Rect — A rectangle representing the texture's bounds.

has_usage

method
has_usage(self, usage: TextureUsage) -> bool

Check whether the texture was created with a specific usage flag.

Args

  • usage (TextureUsage) — Usage flag to test.

Returns

  • bool — True if the usage flag is present.

Find your next step

Start typing to search the manual.