纹理地图集#
arcade.AtlasRegion#
arcade.TextureAtlas#
- class arcade.TextureAtlas(size: Tuple[int, int], *, border: int = 1, textures: Sequence[Texture] = None, auto_resize: bool = True, ctx: ArcadeContext = None)[源代码]#
具有上下文中的大小的纹理图集。
纹理图集是包含多个纹理的大型纹理,因此OpenGL可以轻松地在一次绘制操作中批量绘制数千或数十万个精灵。
这是一个相当简单的地图集,存储水平条带,条带的高度是纹理/图像与大的高度。
将纹理添加到此贴图集将生成纹理ID。此id用于使用精灵列表顶点数据来引用每个精灵使用的纹理。实际的纹理坐标位于一个浮动32纹理中,该图集负责保持最新。
- 参数
- add(texture: Texture) Tuple[int, arcade.texture_atlas.AtlasRegion] [源代码]#
将纹理添加到地图集。
- 参数
texture (Texture) -- 要添加的纹理
- 返回
Texture_id,AtlasRegion元组
- allocate(texture: Texture) Tuple[int, int, int, arcade.texture_atlas.AtlasRegion] [源代码]#
尝试为贴图集中的纹理分配空间。这不会将纹理写入贴图集纹理本身。它只分配空间。
- 返回
纹理区域的x,y纹理_id
- classmethod calculate_minimum_size(textures: Sequence[Texture], border: int = 1)[源代码]#
计算存储所提供的纹理序列所需的最小图集大小
- 参数
textures (Sequence[Texture]) -- 纹理序列
border --
- 返回
估计的最小大小,以(宽度、高度)元组表示
- clear(texture_ids: bool = True, texture: bool = True) None [源代码]#
清除并重置纹理图集。请注意,同时清除“Texture_ID”会使贴图集失去旧纹理ID的跟踪。这意味着精灵列表必须从头开始重建。
- classmethod create_from_texture_sequence(textures: Sequence[Texture], border: int = 1) TextureAtlas [源代码]#
从一系列纹理创建一个大小合理的纹理贴图集。
- property fbo: arcade.gl.framebuffer.Framebuffer#
此贴图集的帧缓冲区对象
- get_region_info(name: str) arcade.texture_atlas.AtlasRegion [源代码]#
获取纹理的区域信息
- 返回
给定纹理名称的AtlasRegion
- remove(texture: Texture) None [源代码]#
从贴图集中删除纹理。
这不会从底层纹理中删除图像。要以物理方式删除您需要的数据
rebuild()
。- 参数
texture (Texture) -- 要删除的纹理
- render_into(texture: Texture, projection: Tuple[float, float, float, float] = None)[源代码]#
直接渲染到地图集的一个子部分中。子部分由此方法中提供的纹理的已分配空间定义。
默认情况下,投影将设置为与纹理区域大小匹配 0, 0 是左下角, width, height (指纹理)是右上角。
此方法应与
with
声明::with atlas.render_into(texture): # Draw commands here # Specify projection with atlas.render_into(texture, projection=(0, 100, 0, 100)) # Draw geometry
- resize(size: Tuple[int, int]) None [源代码]#
在GPU上调整地图集的大小。
这将把像素数据从旧的地图集复制到新的地图集,保留完全相同的数据。如果地图集是直接渲染到中的,并且我们不必将每个纹理从系统内存单独传输到图形内存,这将非常有用。
- save(path: str, flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) None [源代码]#
将纹理贴图集保存为PNG。
- show(flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) None [源代码]#
使用枕头显示纹理图集
- to_image(flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) PIL.Image.Image [源代码]#
将地图集转换为枕头图像
- update_texture_image(texture: Texture)[源代码]#
更新贴图集纹理中纹理的内部图像。新的图像需要与原始图像的大小完全相同,这意味着纹理需要已经存在于地图集中。
这可以用在图像被以某种方式处理的情况下,我们需要一种快速的方法将这些更改同步到图形内存。这项操作相当昂贵,但仍比移除旧纹理、添加新纹理并重建整个地图集快几个数量级。
- 参数
texture (Texture) -- 要更新的纹理
- use_uv_texture(unit: int = 0) None [源代码]#
将纹理坐标纹理绑定到通道。此外,如果数据过时,则此方法将纹理坐标写入纹理。这是为了避免每次将纹理添加到贴图集时进行完全更新。
- 参数
unit (int) -- 用于绑定UV纹理的纹理单位
- write_image(image: PIL.Image.Image, x: int, y: int) None [源代码]#
将PIL图像写入特定地区的地图集。
- 参数
image (PIL.Image.Image) -- 枕头形象
x (int) -- 写入纹理的x位置
y (int) -- 写入纹理的y位置