pyglet.image.atlas
将多个小图像组合成较大的纹理。
此模块由使用 pyglet.resource
将小图像高效地打包到较大的纹理中。 TextureAtlas
保持一种纹理; TextureBin
管理给定大小的地图集。
示例用法::
# Load images from disk
car_image = pyglet.image.load('car.png')
boat_image = pyglet.image.load('boat.png')
# Pack these images into one or more textures
bin = TextureBin()
car_texture = bin.add(car_image)
boat_texture = bin.add(boat_image)
其结果是 TextureBin.add()
是一种 TextureRegion
包含该图像的。图像一旦添加,就不能从图库(或地图集)中删除;也不能从给定的图库或图集中获得图像列表--应用程序负责跟踪 add
方法:研究方法。
在 1.1 版本加入.
- exception AllocatorException
分配器没有足够的可用空间来容纳所请求的图像大小。
- class Allocator(width: int, height: int)
矩形面积分配算法。
使用给定的
width
和height
,然后重复调用 alloc 以检索该区域的空闲区域并保护该区域不受未来分配的影响。Allocator 使用相当简单的基于条带的算法。当矩形按高度递减顺序分配时,它的性能最佳。
- alloc(width: int, height: int) Tuple[int, int]
在分配器中获得给定大小的空闲区域。
在呼叫之后 alloc ,则不再使用请求的区域。如果没有足够的空间来容纳给定的区域 AllocatorException 都被养大了。
- height
- strips
- used_area
- width
- class TextureArrayBin(texture_width: int = 2048, texture_height: int = 2048, max_depth: int | None = None)
纹理数组的集合。
TextureArrayBin
维护纹理数组的集合,并在超过深度时根据需要创建新的纹理数组。- add(img: AbstractImage) TextureArrayRegion
将图像添加到此纹理数组框中。
此方法调用 TextureArray.add 用于具有图像空间的第一个数组。
TextureArraySizeExceeded 如果图像的尺寸超过
texture_width
和texture_height
。- 参数:
- img~pyglet.image.AbstractImage
要添加的图像。
- 返回类型:
TextureArrayRegion
- 返回:
包含新添加的图像的数组区域。
- class TextureAtlas(width: int = 2048, height: int = 2048)
纹理中的图像集合。
- add(img: AbstractImage, border: int = 0) TextureRegion
将图像添加到地图集。
如果给定的图像无法直接传递到纹理(例如,如果它是另一个纹理),则此方法将失败。
ImageData
是此方法的常用图像类型。AllocatorException 如果地图集中没有空间放置图像,则将引发。
- 参数:
- img~pyglet.image.AbstractImage
要添加的图像。
- border集成
在添加到地图集的每个图像周围保留指定像素的空白空间。
- 返回类型:
- 返回:
包含新添加的图像的地图集区域。
- class TextureBin(texture_width: int = 2048, texture_height: int = 2048)
纹理地图集。
TextureBin
维护纹理贴图集,并根据需要创建新的纹理贴图集以容纳添加到存储箱中的图像。- add(img: AbstractImage, border: int = 0) TextureRegion
将图像添加到此纹理框中。
此方法调用 TextureAtlas.add 为第一个有空间放置图像的地图集。
AllocatorException 如果图像的尺寸超过
texture_width
和texture_height
。- 参数:
- img~pyglet.image.AbstractImage
要添加的图像。
- border集成
在添加到地图集的每个图像周围保留指定像素的空白空间。
- 返回类型:
- 返回:
包含新添加的图像的地图集区域。