纹理管理#

arcade.Texture#

class arcade.Texture(name: str, image: Optional[PIL.Image.Image] = None, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5)[源代码]#

类的新实例,它表示纹理。通常由 load_textureload_textures 命令。

参数
  • name (str) -- 纹理的名称。用于缓存,因此对于每个纹理必须是唯一的。

  • image (PIL.Image.Image) -- 用作纹理的图像。

  • hit_box_algorithm (str) -- “无”、“无”、“简单”或“详细”之一。默认为‘Simple’。使用‘Simple’表示 PhysicsEngineSimplePhysicsEnginePlatformer ,并为 PymunkPhysicsEngine 。。。Figure::../Images/HIT_BOX_ALGORM_NONE.png:宽度:40%HIT_BOX_ALGORITY=“无”..Figure::../Images/HIT_BOX_ALGORM_SIMPLE.png:宽度:55%HIT_BOX_ALGORITY=“Simple”..图::../Images/HIT_BOX_ALGORM_Detailed.png:宽度:75%HIT_BOX_ALGORITY=“DETAILED”

  • hit_box_detail (float) -- 浮动,默认为4.5。与‘Detail’连用表示命中空格

属性:
名字

纹理的唯一名称。由LOAD_TEXTIES用于缓存。如果要手动创建纹理,只需将其设置为任何值即可。

图像

A PIL.Image.Image 对象。

宽度

纹理的宽度,以像素为单位。

高度

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

大小

包含(宽度、高度)的元组

hit_box_points

纹理的计算命中框

classmethod create_empty(name: str, size: Tuple[int, int]) arcade.texture.Texture[源代码]#

创建一个所有像素都设置为透明黑色的纹理。

返回纹理的点击框将被设置为矩形,其尺寸在 size 因为没有非空白像素数据来计算命中框。

参数
  • name (str) -- 此纹理的唯一名称

  • size (Tuple[int,int]) -- 内部图像的XY大小

此功能有多种用途,包括:

  • 在纹理贴图集中分配空间

  • 从组件图像生成自定义缓存纹理

内部图像可以用枕头绘制命令更改,然后写入/更新到纹理图集。这最适用于不频繁的更改,例如生成自定义缓存子画面。对于频繁的纹理更改,应改为直接渲染到纹理贴图集。

警告

如果您计划使用枕头更改图像,请仔细阅读其文档!其中一些函数可能具有意外的行为。

例如,如果要将一个或多个包含透明度的图像绘制到也包含透明度的基本图像上,则可能需要使用 PIL.Image.alpha_composite 作为您的解决方案的一部分。否则,混合可能会以意外的方式进行。

这对于可定制的角色尤其重要。

使用此函数时,请注意内存的使用情况。此方法返回的纹理将有一个新的内部RGBA Pillow图像,其中的每个像素使用4个字节。如果您创建了许多大型纹理,这将很快累积起来。

如果要创建多个具有相同尺寸的空白纹理,可以通过调用此函数一次,然后将 image 属性设置为要创建的每个附加空白纹理实例的类构造函数。如果要创建多个大型纹理,这会特别有用。

draw_scaled(center_x: float, center_y: float, scale: float = 1.0, angle: float = 0, alpha: int = 255)[源代码]#

绘制纹理。

参数
  • center_x (float) -- 绘制纹理的位置的X位置。

  • center_y (float) -- 绘制纹理的Y位置。

  • scale (float) -- 缩放以绘制矩形。默认为1。

  • angle (float) -- 旋转纹理的角度。

  • alpha (int) -- 纹理的透明度 (0-255)

draw_sized(center_x: float, center_y: float, width: float, height: float, angle: float = 0, alpha: int = 255)[源代码]#

绘制具有特定宽度和高度的纹理。

property height: int#

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

property size: Tuple[int, int]#

作为元组的宽度和高度

property width: int#

纹理的宽度,以像素为单位。

arcade.cleanup_texture_cache#

arcade.cleanup_texture_cache()[源代码]#

这将清除纹理的缓存。在运行单元测试以便下一个测试开始时非常有用。

arcade.load_spritesheet#

arcade.load_spritesheet(file_name: Union[str, pathlib.Path], sprite_width: int, sprite_height: int, columns: int, count: int, margin: int = 0, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5) List[arcade.texture.Texture][源代码]#
参数
  • file_name (str) -- 保存纹理的文件的名称。

  • sprite_width (int) -- 精灵的宽度,以像素为单位

  • sprite_height (int) -- 精灵的高度,以像素为单位

  • columns (int) -- 图像宽度的平铺数。

  • count (int) -- 图像中的平铺数量。

  • margin (int) -- 图像之间的边距

  • hit_box_algorithm (str) -- None、‘None’、‘Simple’(默认)或‘Detail’之一。

  • hit_box_detail (float) -- 浮动,默认为4.5。与‘Detail’连用表示命中空格

退货列表

列表: Texture 对象。

arcade.load_texture#

arcade.load_texture(file_name: Union[str, pathlib.Path], x: float = 0, y: float = 0, width: float = 0, height: float = 0, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, can_cache: bool = True, mirrored: Optional[bool] = None, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5) arcade.texture.Texture[源代码]#

从磁盘加载图像并创建纹理。

注意:如果代码只加载图像的一部分,则给定的 xy 坐标将从原点开始 (0, 0) 在图像的左上角。绘制时,Arcade使用 (0, 0) 在左下角。对这种反转要小心。

有关计算机有时在左上角启动的详细说明,请参阅:http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

参数
  • file_name (str) -- 保存纹理的文件的名称。

  • x (float) -- 纹理裁剪区域的X位置。

  • y (float) -- 纹理的裁剪区域的Y位置。

  • width (float) -- 纹理的裁剪区域的宽度。

  • height (float) -- 纹理的裁剪区域的高度。

  • flipped_horizontally (bool) -- 镜像精灵图像。沿垂直轴向左/向右翻转。

  • flipped_vertically (bool) -- 沿水平轴向上/向下翻转图像。

  • flipped_diagonally (bool) -- 转置图像,将其沿对角线翻转。

  • can_cache (bool) -- 如果已加载纹理,则Load_Texture将返回相同的纹理以节省时间。有时这并不理想,因为调整缓存纹理的大小会导致所有其他纹理也随之调整大小。如果将CAN_CACHE设置为FALSE,则会在使用其他资源的情况下避免此问题。

  • mirrored (bool) -- 已弃用。

  • hit_box_algorithm (str) -- “无”、“无”、“简单”或“详细”之一。默认为‘Simple’。使用‘Simple’表示 PhysicsEngineSimplePhysicsEnginePlatformer ,并为 PymunkPhysicsEngine 。。。Figure::../Images/HIT_BOX_ALGORM_NONE.png:宽度:40%HIT_BOX_ALGORITY=“无”..Figure::../Images/HIT_BOX_ALGORM_SIMPLE.png:宽度:55%HIT_BOX_ALGORITY=“Simple”..图::../Images/HIT_BOX_ALGORM_Detailed.png:宽度:75%HIT_BOX_ALGORITY=“DETAILED”

  • hit_box_detail (float) -- 浮动,默认为4.5。与‘Detail’连用表示命中空格

返回

新的 Texture 对象。

加薪

ValueError

arcade.load_texture_pair#

arcade.load_texture_pair(filename, hit_box_algorithm: str = 'Simple')[源代码]#

加载纹理对,第二个纹理对是第一个纹理对的镜像。在制作动画时非常有用,并且角色可以面向左/右。

arcade.load_textures#

arcade.load_textures(file_name: Union[str, pathlib.Path], image_location_list: Union[Tuple[Union[Tuple[float, float, float, float], List[float]], ...], List[Union[Tuple[float, float, float, float], List[float]]]], mirrored: bool = False, flipped: bool = False, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5) List[arcade.texture.Texture][源代码]#

从单个图像文件加载一组纹理。

注意:如果代码只加载图像的一部分,则给定的 xy 坐标将从原点开始 (0, 0) 在图像的左上角。绘制时,Arcade使用 (0, 0) 在左下角。对这种反转要小心。

有关计算机有时在左上角启动的详细说明,请参阅:http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

参数
  • file_name (str) -- 文件的名称。

  • image_location_list (List) -- 图像子位置列表。每个矩形应该是一个 List 在四个浮点数中: [x, y, width, height]

  • mirrored (bool) -- 如果设置为 True ,图像从左到右镜像。

  • flipped (bool) -- 如果设置为 True ,图像被颠倒了。

  • hit_box_algorithm (str) -- None、‘None’、‘Simple’(默认)或‘Detail’之一。

  • hit_box_detail (float) -- 浮动,默认为4.5。与‘Detail’连用表示命中空格

返回

列表: Texture 的。

加薪

ValueError

arcade.make_circle_texture#

arcade.make_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], name: Optional[str] = None) arcade.texture.Texture[源代码]#

返回具有给定直径和颜色的圆的纹理。

参数
  • diameter (int) -- 圆的直径和正方形的尺寸 Texture 回来了。

  • color (Color) -- 圆的颜色。

  • name (str) -- 此纹理的自定义名称或预先选择的名称

返回

新的 Texture 对象。

arcade.make_soft_circle_texture#

arcade.make_soft_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0, name: Optional[str] = None) arcade.texture.Texture[源代码]#

返回一个 Texture 指具有给定直径和颜色的圆,在其边缘淡出。

参数
  • diameter (int) -- 圆的直径和正方形的尺寸 Texture 回来了。

  • color (Color) -- 圆的颜色。

  • center_alpha (int) -- 位于圆心的圆的Alpha值。

  • outer_alpha (int) -- 圆在其边上的Alpha值。

  • name (str) -- 此纹理的自定义名称或预先选择的名称

返回

新的 Texture 对象。

返回类型

arcade.Texture

arcade.make_soft_square_texture#

arcade.make_soft_square_texture(size: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0, name: Optional[str] = None) arcade.texture.Texture[源代码]#

返回一个 Texture 指具有给定直径和颜色的正方形,在其边缘淡出。

参数
  • size (int) -- 返回的正方形的直径和正方形纹理的尺寸。

  • color (Color) -- 正方形的颜色。

  • center_alpha (int) -- 正方形中心的Alpha值。

  • outer_alpha (int) -- 正方形在其边缘的Alpha值。

  • name (str) -- 此纹理的自定义名称或预先选择的名称

返回

新的 Texture 对象。

arcade.trim_image#

arcade.trim_image(image: PIL.Image.Image) PIL.Image.Image[源代码]#

从图像中裁剪出额外的空格。

返回

新的 PIL.Image.Image 对象。