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.
At a glance
7 membersReference
PYTHON APITexture(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.
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.
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.
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
propertyheight: intThe height of the texture in pixels.
size
propertysize: Vec2The dimensions of the texture as a Vec2.
usage
propertyusage: TextureUsageThe usage flags describing how the texture can be used.
Returns
- TextureUsage — The texture usage bitmask.
width
propertywidth: intThe width of the texture in pixels.
get_rect
methodget_rect(self) -> RectReturn a Rect with position (0, 0) and the texture's dimensions.
Returns
- Rect — A rectangle representing the texture's bounds.
has_usage
methodhas_usage(self, usage: TextureUsage) -> boolCheck 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.