纹理管理#
- arcade.load_spritesheet(file_name: str | Path, sprite_width: int, sprite_height: int, columns: int, count: int, margin: int = 0, hit_box_algorithm: HitBoxAlgorithm | None = None) List[Texture] [源代码]#
- 参数:
file_name -- 保存纹理的文件的名称。
sprite_width -- 精灵的宽度,以像素为单位
sprite_height -- 精灵的高度,以像素为单位
columns -- 图像宽度的平铺数。
count -- 图像中的平铺数量。
margin -- 图像之间的边距
hit_box_algorithm -- 命中盒算法
- 退货列表:
列表
Texture
物体。
- arcade.load_texture(file_path: str | Path, *, x: int = 0, y: int = 0, width: int = 0, height: int = 0, hit_box_algorithm: HitBoxAlgorithm | None = None) Texture [源代码]#
从磁盘加载图像并创建纹理。
这个
x
,y
,width
,以及height
参数用于指定要加载的图像的子矩形。如果未指定,则加载整个图像。- 参数:
file_name -- 保存纹理的文件的名称。
x -- 图像中纹理的X坐标。
y -- 图像中纹理的Y坐标。
width -- 图像中纹理的宽度。
height -- 图像中纹理的高度。
hit_box_algorithm --
- 返回:
新的
Texture
对象。- 加薪:
ValueError
- arcade.load_texture_pair(file_name: str | Path, hit_box_algorithm: HitBoxAlgorithm | None = None) Tuple[Texture, Texture] [源代码]#
加载纹理对,第二个纹理对是第一个纹理对的镜像。在制作动画时非常有用,并且角色可以面向左/右。
- 参数:
file_name -- 纹理路径
hit_box_algorithm -- 命中盒算法
- arcade.load_textures(file_name: str | Path, image_location_list: Tuple[Tuple[int, int, int, int] | List[int], ...] | List[Tuple[int, int, int, int] | List[int]], mirrored: bool = False, flipped: bool = False, hit_box_algorithm: HitBoxAlgorithm | None = None) List[Texture] [源代码]#
从单个图像文件加载一组纹理。
注意:如果代码只加载图像的一部分,则给定的 x , y 坐标将从原点开始 (0, 0) 在图像的左上角。绘制时,Arade使用 (0, 0) 在左下角。对这种反转要小心。
有关计算机有时在左上角启动的详细说明,请参阅:http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5
- 参数:
file_name -- 文件的名称。
image_location_list -- 图像子位置列表。每个矩形应该是一个 List 在四个浮点数中: [x, y, width, height] 。
mirrored -- 如果设置为 True ,图像从左到右镜像。
flipped -- 如果设置为 True ,图像被颠倒了。
hit_box_algorithm -- None、‘None’、‘Simple’(默认)或‘Detail’之一。
hit_box_detail -- 浮动,默认为4.5。与‘Detail’连用表示命中空格
- 返回:
列表
Texture
的。- 加薪:
ValueError
- class arcade.Texture(image: Image | ImageData, *, hit_box_algorithm: HitBoxAlgorithm | None = None, hit_box_points: Sequence[Tuple[float, float]] | None = None, hash: str | None = None, **kwargs)[源代码]#
基类:
Arcade.Texture只是将图像数据包装为Pillow图像,并将该图像的命中框数据用于碰撞检测。通常由
load_texture
或load_textures
命令。- 参数:
image -- 此纹理的图像或ImageData
hit_box_algorithm -- 用于计算命中框的算法。
hit_box_points -- 要使用的纹理的Hitbox点列表(可选)。完全覆盖命中框算法。
hash -- 纹理的可选唯一名称。可用于使该纹理全局唯一。默认情况下,使用像素数据的散列。
- add_atlas_ref(atlas: TextureAtlas) None [源代码]#
添加对此纹理所在的地图集的引用。
- classmethod create_atlas_name(hash: str, vertex_order: Tuple[int, int, int, int] = (0, 1, 2, 3))[源代码]#
- classmethod create_cache_name(*, hash: str, hit_box_algorithm: HitBoxAlgorithm, vertex_order: Tuple[int, int, int, int] = (0, 1, 2, 3)) str [源代码]#
为纹理创建缓存名称。
- classmethod create_empty(name: str, size: Tuple[int, int], color: Tuple[int, int, int, int] = (0, 0, 0, 0)) Texture [源代码]#
创建一个所有像素都设置为透明黑色的纹理。
返回纹理的点击框将被设置为矩形,其尺寸在
size
因为没有非空白像素数据来计算命中框。- 参数:
name -- 此纹理的唯一名称
size -- 内部图像的XY大小
此功能有多种用途,包括:
在纹理贴图集中分配空间
从组件图像生成自定义缓存纹理
内部图像可以用枕头绘制命令更改,然后写入/更新到纹理图集。这最适用于不频繁的更改,例如生成自定义缓存子画面。对于频繁的纹理更改,应改为直接渲染到纹理贴图集。
警告
如果您计划使用枕头更改图像,请仔细阅读其文档!其中一些函数可能具有意外的行为。
例如,如果要将一个或多个包含透明度的图像绘制到也包含透明度的基本图像上,则可能需要使用 PIL.Image.alpha_composite 作为您的解决方案的一部分。否则,混合可能会以意外的方式进行。
这对于可定制的角色尤其重要。
使用此函数时,请注意内存的使用情况。此方法返回的纹理将有一个新的内部RGBA Pillow图像,其中的每个像素使用4个字节。如果您创建了许多大型纹理,这将很快累积起来。
如果要创建多个具有相同尺寸的空白纹理,可以通过调用此函数一次,然后将
image
属性设置为要创建的每个附加空白纹理实例的类构造函数。如果要创建多个大型纹理,这会特别有用。
- classmethod create_filled(name: str, size: Tuple[int, int], color: Tuple[int, int, int, int]) Texture [源代码]#
创建填充纹理。这是的别名
create_empty()
。
- classmethod create_image_cache_name(path: str | Path, crop: Tuple[int, int, int, int] = (0, 0, 0, 0))[源代码]#
- crop(x: int, y: int, width: int, height: int) Texture [源代码]#
从该纹理的子部分创建新纹理。
如果裁剪的大小与原始纹理相同,或者裁剪的宽度或高度为0,则返回原始纹理。
- 参数:
x -- 开始裁剪的X位置
y -- 开始裁剪的Y位置
width -- 裁剪宽度
height -- 作物株高
cache -- 如果为True,则将缓存裁剪的纹理
- 返回:
纹理
- draw_scaled(center_x: float, center_y: float, scale: float = 1.0, angle: float = 0.0, alpha: int = 255)[源代码]#
绘制纹理。
警告
这是绘制纹理的一种非常慢的方法,应该谨慎使用。该方法只是在内部创建一个精灵并绘制它。
- 参数:
center_x -- 绘制纹理的位置的X位置。
center_y -- 绘制纹理的Y位置。
scale -- 缩放以绘制矩形。默认为1。
angle -- 旋转纹理的角度。
alpha -- 纹理的透明度 (0-255) 。
- draw_sized(center_x: float, center_y: float, width: float, height: float, angle: float = 0.0, alpha: int = 255)[源代码]#
绘制具有特定宽度和高度的纹理。
警告
这是绘制纹理的一种非常慢的方法,应该谨慎使用。该方法只是在内部创建一个精灵并绘制它。
- 参数:
center_x -- 绘制纹理的X位置
center_y -- 绘制纹理的Y位置
width -- 绘制纹理的宽度
height -- 绘制纹理的高度
angle -- 绘制纹理的角度
alpha -- 绘制纹理的Alpha值
- flip_diagonally() Texture [源代码]#
返回从该纹理沿对角线翻转的新纹理。这是的别名
transpose()
。这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- flip_horizontally() Texture [源代码]#
将纹理从左向右/水平翻转。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- flip_left_right() Texture [源代码]#
将纹理从左向右/水平翻转。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- flip_top_bottom() Texture [源代码]#
从上到下/垂直翻转纹理。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- flip_vertically() Texture [源代码]#
从上到下/垂直翻转纹理。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- remove_atlas_ref(atlas: TextureAtlas) None [源代码]#
删除对此纹理所在的贴图集的引用。
- remove_from_cache(ignore_error: bool = True) None [源代码]#
从缓存中移除该纹理。
- 参数:
ignore_error -- 如果为True,则在纹理不在缓存中时忽略错误
- 返回:
无
- rotate_90(count: int = 1) Texture [源代码]#
按给定的90度步数旋转纹理。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 参数:
count -- 要旋转的90度台阶数。
- 返回:
纹理
- transpose() Texture [源代码]#
返回从该纹理转置的新纹理。这将从右下角对角线翻转纹理到左上角。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- transverse() Texture [源代码]#
返回与此纹理横向的新纹理。这将从左下角对角线翻转纹理到右上角。
这将返回具有相同图像数据的新纹理,但已更新命中框数据和将在绘制图像时应用于图像的变换(GPU端)。
- 返回:
纹理
- atlas_name#
用于纹理贴图集的纹理名称(只读)。
- 返回:
应力
- cache_name#
用于缓存的纹理的名称(只读)。
- 返回:
应力
- crop_values#
用于在被引用文件中创建此纹理的裁剪值
- 返回:
元组 [int, int, int, int]
- file_path#
从中加载此纹理的文件的路径对象
- 返回:
路径
- height#
纹理的虚拟宽度,以像素为单位。
如果纹理已变换或已手动设置大小,则此宽度可能与实际宽度不同。
- hit_box_algorithm#
(只读)用于计算此纹理的命中框的算法。
- hit_box_points#
获取此纹理的命中框点数。
自定义点击框点必须在纹理创建过程中提供,最好不要在创建后更改。
- 返回:
PointList
- image#
获取或设置纹理的图像。
警告
这是一个高级功能。绝对要确保你知道改变形象的后果。它可能会导致纹理图集和命中框点的问题。
- 参数:
image -- 要设置的图像
- image_data#
纹理的图像数据(只读)。
这是一个包含散列等元数据的简单图像包装器,用于确定图像在纹理图集中的唯一性。
- 返回:
ImageData
- properties#
此纹理的属性词典。这可以用来存储您想要的任何数据。
- 返回:
迪克特 [str, Any]
- size#
纹理的虚拟大小,以像素为单位。
如果纹理已变换或已手动设置大小,则此宽度可能与实际宽度不同。
- width#
纹理的虚拟宽度,以像素为单位。如果纹理已变换或已手动设置大小,则此宽度可能与实际宽度不同。
- class arcade.TextureManager[源代码]#
基类:
此类用于管理纹理。它用于跟踪已加载的纹理,并确保不会两次加载相同的纹理。
通过该管理器加载的纹理在内部缓存。
- flush(sprite_sheets: bool = True, textures: bool = True, image_data: bool = True, hit_boxes: bool = False)[源代码]#
从纹理管理器中移除内容。
- 参数:
sprite_sheets -- 如果
True
,精灵床单将被冲洗。textures -- 如果
True
,纹理将被刷新。image_data -- 如果
True
,图像数据将被刷新。hit_boxes -- 如果
True
,命中框将被刷新。
- arcade.make_circle_texture(diameter: int, color: Tuple[int, int, int, int], name: str | None = None, hitbox_algorithm: HitBoxAlgorithm | None = None) Texture [源代码]#
返回具有给定直径和颜色的圆的纹理。
- arcade.make_soft_circle_texture(diameter: int, color: Tuple[int, int, int, int], center_alpha: int = 255, outer_alpha: int = 0, name: str | None = None, hit_box_algorithm: HitBoxAlgorithm | None = None) Texture [源代码]#
返回一个
Texture
指具有给定直径和颜色的圆,在其边缘淡出。
- arcade.make_soft_square_texture(size: int, color: Tuple[int, int, int, int], center_alpha: int = 255, outer_alpha: int = 0, name: str | None = None) Texture [源代码]#
返回一个
Texture
指具有给定直径和颜色的正方形,在其边缘淡出。- 参数:
size -- 返回的正方形的直径和正方形纹理的尺寸。
color -- 正方形的颜色。
center_alpha -- 正方形中心的Alpha值。
outer_alpha -- 正方形在其边缘的Alpha值。
name -- 此纹理的自定义名称或预先选择的名称
- 返回:
新的
Texture
对象。
- arcade.get_default_image(size: Tuple[int, int] = (128, 128)) ImageData [源代码]#
生成并返回默认图像,并在内部缓存该图像以供将来使用。
- 参数:
size -- 要创建的图像的大小。
- 返回:
默认图像。
- arcade.get_default_texture(size: Tuple[int, int] = (128, 128)) Texture [源代码]#
创建并返回默认纹理,并在内部缓存该纹理以供将来使用。
- 参数:
size -- 要创建的纹理的大小
- 返回:
默认纹理。
- class arcade.SpriteSheet(path: str | Path | None = None, image: Image | None = None)[源代码]#
基类:
类来保存精灵工作表。精灵工作表是包含多个纹理的单个图像。通过裁剪图像的各个部分,可以从精灵工作表创建纹理。
这只是一个实用程序类。它没有任何特殊功能
- 参数:
path -- 要加载的文件的路径。
image -- 要使用的PIL图像。
- crop(area: Tuple[int, int, int, int] | List[int])[源代码]#
从精灵薄板裁剪纹理。
- 参数:
area -- 要裁剪的区域
(x, y, width, height)
- crop_grid(size: Tuple[int, int], columns: int, count: int, margin: Tuple[int, int, int, int] | List[int] = (0, 0, 0, 0), hit_box_algorithm: HitBoxAlgorithm | None = None) List[Texture] [源代码]#
从精灵工作表中裁剪纹理栅格。
- 参数:
size -- 每个纹理的大小
(width, height)
columns -- 网格中的列数
count -- 要裁剪的纹理数量
margin -- 每种纹理周围的边距
(left, right, bottom, top)
hit_box_algorithm -- 用于纹理的命中框算法。
- crop_sections(sections: List[Tuple[int, int, int, int] | List[int]])[源代码]#
通过指定要裁剪的区域列表,从精灵工作表中裁剪多个纹理。
- 参数:
sections -- 要裁剪的区域列表
[(x, y, width, height), ...]
- flip_flags#
查询精灵板材的方向。这可用于确定是否需要翻转精灵工作表。
缺省值为
(False, False)
。将在以下情况下修改flip_left_right()
或flip_top_bottom()
被称为。- 返回:
布尔元组
(flip_left_right, flip_top_bottom)
。
- image#
获取或设置此精灵工作表的PIL图像。
- path#
通往精灵工作表的路径。
- 返回:
这条路。