纹理地图集#

arcade.AtlasRegion#

class arcade.AtlasRegion(atlas: TextureAtlas, texture: Texture, x: int, y: int, width: int, height: int)[源代码]#

存储有关纹理位置的信息

参数
  • atlas (str) -- 该地区所属的地图集

  • texture (str) -- Arcade纹理

  • x (int) -- 纹理的x位置

  • y (int) -- 纹理的y位置

  • width (int) -- 纹理的宽度(以像素为单位

  • height (int) -- 纹理的高度,以像素为单位

verify_image_size()[源代码]#

验证图像大小是否正确。纹理的内部图像可以在任何时候被篡改,从而导致地图集更新失败。

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纹理中,该图集负责保持最新。

参数
  • size (Tuple[int, int]) -- 以像素为单位的地图集的宽度和高度

  • border (int) -- 当前没有效果;应始终为1以避免纹理渗漏

  • textures (Sequence[arcade.Texture]) -- 这本地图集的纹理

  • auto_resize (bool) -- 已满时自动调整地图集大小

  • ctx (Context) -- 此图片集的上下文(如果保留为空,将使用窗口上下文)

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

property auto_resize: bool#

获取或设置地图集的自动调整大小标志。如果启用,地图集将在满时自动调整大小。

返回类型

bool

property border: int#

以像素为单位的纹理边框

返回类型

int

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的跟踪。这意味着精灵列表必须从头开始重建。

参数
  • texture_ids (bool) -- 清除指定的纹理ID

  • texture (bool) -- 清除贴图集纹理本身的内容

classmethod create_from_texture_sequence(textures: Sequence[Texture], border: int = 1) TextureAtlas[源代码]#

从一系列纹理创建一个大小合理的纹理贴图集。

参数
  • textures (Sequence[Texture]) -- 纹理序列(列表、集、元组、生成器等)

  • border (int) -- 贴图集的边框(以像素为单位)(每个纹理之间的间距)

property fbo: arcade.gl.framebuffer.Framebuffer#

此贴图集的帧缓冲区对象

get_region_info(name: str) arcade.texture_atlas.AtlasRegion[源代码]#

获取纹理的区域信息

返回

给定纹理名称的AtlasRegion

get_texture_id(name: str) int[源代码]#

获取纹理名称的UV窗

返回

给定纹理名称的纹理ID

has_texture(texture: Texture) bool[源代码]#

检查纹理是否已在贴图集中

property height: int#

纹理图集的高度,以像素为单位

返回类型

int

property max_height: int#

地图集的最大高度(以像素为单位

返回类型

int

property max_size: Tuple[int, int]#

地图集的最大大小(以像素为单位)(x,y)

返回类型

Tuple[int,int]

property max_width: int#

地图集的最大宽度(以像素为单位

返回类型

int

rebuild() None[源代码]#

重建基础贴图集纹理。

该方法还尝试更有效地组织纹理,按大小对它们进行排序。纹理ID将保持不变,因此精灵列表不需要重建。

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
参数
  • texture (Texture) -- 要渲染到的纹理区域

  • projection (Tuple[float,float,float,float]) -- 要用于渲染的正交投影。如果不需要更改投影,则可以将此参数留空。元组值为:(Left、Right、Button、Top)

resize(size: Tuple[int, int]) None[源代码]#

在GPU上调整地图集的大小。

这将把像素数据从旧的地图集复制到新的地图集,保留完全相同的数据。如果地图集是直接渲染到中的,并且我们不必将每个纹理从系统内存单独传输到图形内存,这将非常有用。

参数

size (Tuple[int,int]) -- 新尺码

save(path: str, flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) None[源代码]#

将纹理贴图集保存为PNG。

参数
  • path (str) -- 将地图集保存到磁盘上的路径

  • flip (bool) -- 水平翻转图像

  • components (int) -- 组件数量。(3=RGB,4=RGBA)

  • color -- 边框的RGB颜色

返回

包含贴图集纹理的枕头图像

show(flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) None[源代码]#

使用枕头显示纹理图集

参数
  • flip (bool) -- 水平翻转图像

  • components (int) -- 组件数量。(3=RGB,4=RGBA)

  • draw_borders (bool) -- 将区域边框绘制为图像

  • color -- 边框的RGB颜色

property size: Tuple[int, int]#

纹理图集的宽度和高度,以像素为单位

返回类型

Tuple[int,int]

property texture: GLTexture#

地图集纹理

返回类型

Texture

to_image(flip: bool = False, components: int = 4, draw_borders: bool = False, border_color: Tuple[int, int, int] = (255, 0, 0)) PIL.Image.Image[源代码]#

将地图集转换为枕头图像

参数
  • flip (bool) -- 水平翻转图像

  • components (int) -- 组件数量。(3=RGB,4=RGBA)

  • draw_borders (bool) -- 将区域边框绘制为图像

  • color -- 边框的RGB颜色

返回

包含贴图集纹理的枕头图像

update_texture_image(texture: Texture)[源代码]#

更新贴图集纹理中纹理的内部图像。新的图像需要与原始图像的大小完全相同,这意味着纹理需要已经存在于地图集中。

这可以用在图像被以某种方式处理的情况下,我们需要一种快速的方法将这些更改同步到图形内存。这项操作相当昂贵,但仍比移除旧纹理、添加新纹理并重建整个地图集快几个数量级。

参数

texture (Texture) -- 要更新的纹理

use_uv_texture(unit: int = 0) None[源代码]#

将纹理坐标纹理绑定到通道。此外,如果数据过时,则此方法将纹理坐标写入纹理。这是为了避免每次将纹理添加到贴图集时进行完全更新。

参数

unit (int) -- 用于绑定UV纹理的纹理单位

property uv_texture: GLTexture#

纹理坐标纹理。

返回类型

Texture

property width: int#

纹理贴图集的宽度(以像素为单位

返回类型

int

write_image(image: PIL.Image.Image, x: int, y: int) None[源代码]#

将PIL图像写入特定地区的地图集。

参数
  • image (PIL.Image.Image) -- 枕头形象

  • x (int) -- 写入纹理的x位置

  • y (int) -- 写入纹理的y位置

write_texture(texture: Texture, x: int, y: int)[源代码]#

将街机纹理写入纹理贴图集的一个子部分