小精灵#

arcade.AnimatedTimeBasedSprite#

class arcade.AnimatedTimeBasedSprite(filename: Optional[str] = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0, _repeat_count_x=1, _repeat_count_y=1)[源代码]#

支持动画的Platform游戏的Sprite。这些可以由平铺地图编辑器自动创建。

update_animation(delta_time: float = 0.016666666666666666)[源代码]#

选择要使用的适当纹理的逻辑。

arcade.AnimatedWalkingSprite#

class arcade.AnimatedWalkingSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)[源代码]#

支持行走动画的Platform游戏不推荐使用Sprite。确保在加载动画后调用UPDATE_动画,以便可以设置初始纹理。或手动设置。

强烈建议您创建此类的您自己的版本,而不是尝试使用这个预打包的版本。

有关示例,请参见Platformer教程的这一节: 第12步-添加角色动画和更好的键盘控制

update_animation(delta_time: float = 0.016666666666666666)[源代码]#

选择要使用的适当纹理的逻辑。

arcade.AnimationKeyframe#

class arcade.AnimationKeyframe(tile_id: int, duration: int, texture: arcade.texture.Texture)[源代码]#

用于动画精灵。

arcade.PyMunk#

class arcade.PyMunk[源代码]#

对象,用于保存精灵的土拨鼠信息。

arcade.Sprite#

class arcade.Sprite(filename: Optional[str] = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0, repeat_count_x: int = 1, repeat_count_y: int = 1, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5, texture: Optional[arcade.texture.Texture] = None, angle: float = 0)[源代码]#

类,该类表示屏幕上的“精灵”。大多数游戏都以精灵为中心。有关如何使用此类的示例,请参阅:https://api.arcade.academy/en/latest/examples/index.html#sprites

参数
  • filename (str) -- 表示精灵的图像的文件名。

  • scale (float) -- 放大或缩小图像。比例为1.0表示无。

  • image_x (float) -- 精灵板内精灵的X偏移量。

  • image_y (float) -- 精灵板内精灵的Y偏移。

  • image_width (float) -- 精灵的宽度

  • image_height (float) -- 精灵的高度

  • center_x (float) -- 精灵的位置

  • center_y (float) -- 精灵的位置

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

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

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

  • hit_box_algorithm (str) -- “无”、“无”、“简单”或“详细”之一。默认为‘Simple’。使用‘Simple’表示 PhysicsEngineSimplePhysicsEnginePlatformer ,并为 PymunkPhysicsEngine

  • texture (Texture) -- 直接指定纹理。

  • angle (float) -- 精灵的初始旋转(以度为单位

这将忽略所有点击框和图像大小参数。

../_images/hit_box_algorithm_none.png

HIT_BOX_ALGORM=“无”#

../_images/hit_box_algorithm_simple.png

HIT_BOX_ALGORM=“简单”#

../_images/hit_box_algorithm_detailed.png

HIT_BOX_ALGORM=“详细”#

参数

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

属性:
Alpha

精灵的透明度。0表示不可见,255表示不透明。

角度

以度为单位的旋转角度。精灵以逆时针方向旋转。

弧度

以弧度为单位的旋转角度。精灵以逆时针方向旋转。

底部

使用底部坐标设置/查询精灵位置。这将是精灵底部的‘y’。

boundary_left

在运动中使用。移动子画面的左边界。

boundary_right

在运动中使用。移动子画面的右边界。

boundary_top

在运动中使用。移动子画面的上边界。

boundary_bottom

在运动中使用。移动子画面的底部边界。

center_x

精灵中心的X位置

center_y

精灵中心的Y位置

change_x

X方向上的移动向量。

change_y

Y方向上的运动矢量。

change_angle

改变旋转方向。

颜色

为精灵上色

collision_radius

用作快速检查,以查看此项目是否与其他项目足够近。如果此检查有效,我们将执行更慢、更准确的检查。您可能不想使用此字段。取而代之的是,在点击框中设置点数。

cur_texture_index

正在使用的当前纹理的索引。

导轨

精灵的唯一标识符。在调试时很有用。

高度

精灵的高度。

应用于精灵的力。与PyMunk一起用于物理时非常有用。

hit_box

用于碰撞检测的相对于精灵中心的点。Arcade默认通过包含图像的“简单”命中框算法创建一个命中框。如果您正在创建一个坡道或制作更好的点击盒,您可以自定义设置这些。

左边

使用左坐标设置/查询精灵位置。这将是精灵左侧的‘x’。

职位

带有精灵所在位置(x,y)的列表。

正确的

使用正确的坐标设置/查询精灵位置。这将是精灵右侧的‘y=x’。

sprite_lists

此精灵所属的所有精灵列表的列表。

织构

arcade.Texture 用当前纹理初始化。设置新纹理会 not 更新精灵的命中框。这可以通过以下方式完成 my_sprite.hit_box = my_sprite.texture.hit_box_points 。新纹理将在当前center_x/center_y上居中。

纹理

与此子画面关联的纹理列表。

塔顶

使用顶部坐标设置/查询精灵位置。这将是精灵顶部的‘y’。

比例尺

放大或缩小图像。比例1.0是原始大小,0.5是高度和宽度的1/2。

速度

X,y的变化,表示为列表。(0,0)不会移动。

宽度

精灵的宽度

这是很常见的超越 update 方法,并提供有关移动或其他精灵更新的机制。

add_spatial_hashes()[源代码]#

将此精灵的空间散列添加到它所属的所有精灵列表中。

property alpha: int#

返回与精灵关联的Alpha。

property angle: float#

获取精灵旋转的角度。

append_texture(texture: arcade.texture.Texture)[源代码]#

将新纹理附加到可应用于该精灵的纹理列表中。

参数

texture (arcade.Texture) -- 要添加到可用纹理列表的纹理

property bottom: float#

返回精灵底部的y坐标。

property center_x: float#

获取精灵的中心x坐标。

property center_y: float#

获取精灵的中心y坐标。

property change_x: float#

得到精灵在x平面上的速度。

property change_y: float#

得到精灵在y平面上的速度。

clear_spatial_hashes()[源代码]#

搜索这个精灵所属的精灵列表,并从它所属的任何空间散列中删除它。

collides_with_list(sprite_list: SpriteList) list[源代码]#

检查当前精灵是否与列表中的任何其他精灵重叠

参数

sprite_list (SpriteList) -- 要检查的SpriteList

返回

原始SpriteList中所有重叠的Sprite的SpriteList

返回类型

SpriteList

collides_with_point(point: Union[Tuple[float, float], List[float]]) bool[源代码]#

检查点是否在当前精灵中。

参数

point (Point) -- 指向检查。

返回

如果点包含在精灵的边界内,则为True。

返回类型

bool

collides_with_sprite(other: arcade.sprite.Sprite) bool[源代码]#

将检查一个精灵是否与另一个精灵重叠(碰撞)。

参数

other (Sprite) -- 另一个要检查的精灵。

返回

对或错,无论它们是否重叠。

返回类型

bool

property collision_radius: float#

获取碰撞半径。

注解

最终碰撞检查是通过在GET_POINTS/SET_POINTS中设置的几何体完成的。这些点在check_for_collision函数中使用。此COLLECT_RADIUS变量用作“预检查”。我们使用Collision_RADIUS执行超快检查,查看精灵是否接近。如果它们是碰撞的,那么我们观察它们是否真的碰撞的几何图形和图形。

property color: Union[Tuple[int, int, int], List[int]]#

返回与精灵关联的RGB颜色。

draw(*, filter=None, pixelated=None, blend_function=None)[源代码]#

画出精灵。

参数
  • filter -- 设置OpenGL滤镜的可选参数,如 gl.GL_NEAREST 以避免平滑。

  • pixelated -- True 对于像素化和 False 用于平滑内插。用于设置Filter=GL_NEAREST的快捷方式。

  • blend_function -- 设置用于绘制精灵列表的OpenGL混合函数的可选参数,例如‘arcade.Window.ctx.BLEND_Additive’或‘arcade.Window.ctx.BLEND_DEFAULT’

draw_hit_box(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0), line_thickness: float = 1)[源代码]#

画一个精灵的命中盒。

‘点击框’绘图被缓存,所以如果您稍后更改颜色/线条粗细,它将不会被缓存。

参数
  • color -- 方框的颜色

  • line_thickness -- 盒子应该有多厚?

face_point(point: Union[Tuple[float, float], List[float]])[源代码]#

将精灵朝向一个点。假设精灵图像朝上。

参数

point (Point) -- 指着面向……。

forward(speed: float = 1.0)[源代码]#

向前调整精灵的移动向量。此方法并不实际移动精灵,只是获取当前的change_x/change_y并按给定的速度进行调整。

参数

speed -- 速度系数

get_adjusted_hit_box() Sequence[Union[Tuple[float, float], List[float]]][源代码]#

获取构成精灵矩形的命中框的点,包括旋转和缩放。

get_hit_box() Sequence[Union[Tuple[float, float], List[float]]][源代码]#

使用Hit_box属性获取或设置精灵的命中框。假设精灵的中心位于(0,0),则指定命中框。指定命中框,如:

mySprite.hit_box = [[-10, -10], [10, -10], [10, 10]]

指定未对平移、旋转或缩放进行调整的点击框。你可以通过以下方式获得调整后的点击框 arcade.Sprite.get_adjusted_hit_box

property height: float#

获取精灵的高度,以像素为单位。

kill()[源代码]#

的别名 remove_from_sprite_lists

property left: float#

返回精灵点击框左侧的x坐标。

on_update(delta_time: float = 0.016666666666666666)[源代码]#

更新子画面。类似于更新,但也需要增量时间。

property position: Union[Tuple[float, float], List[float]]#

获取精灵的中心x和y坐标。

退货:

(CENTER_x,CENTER_Y)

property properties: Dict[str, Any]#

获取或设置自定义子画面属性。

返回类型

Dict[str, Any]

property pymunk: arcade.sprite.PyMunk#

获取或设置Pymunk属性对象。这是由金龟子物理引擎使用的。

pymunk_moved(physics_engine, dx, dy, d_angle)[源代码]#

如果这个精灵移动了,就会被黑猩猩物理引擎调用。

property radians: float#

将self.Angel的度数表示转换为弧度。:RETURN:浮动

register_physics_engine(physics_engine)[源代码]#

在精灵上注册一个物理引擎。只有当您实际上需要引用精灵本身中的物理引擎时,才需要这样做。它没有其他目的。

注册的物理引擎可以通过 physics_engines 属性。

例如,它可以是金龟子的物理引擎,也可以是您定制的引擎。

register_sprite_list(new_list: SpriteList)[源代码]#

将此子画面注册为属于列表。当调用Kill()时,我们将自动从列表中删除自己。

remove_from_sprite_lists()[源代码]#

从所有精灵列表中删除精灵。

rescale_relative_to_point(point: Union[Tuple[float, float], List[float]], factor: float) None[源代码]#

相对于不同于其中心的点重新缩放精灵。

reverse(speed: float = 1.0)[源代码]#

向后调整精灵的移动向量。此方法并不实际移动精灵,只是获取当前的change_x/change_y并按给定的速度进行调整。

参数

speed -- 速度系数

property right: float#

返回精灵点击框右侧的x坐标。

property scale: float#

获取精灵的比例。

set_hit_box(points: Sequence[Union[Tuple[float, float], List[float]]])[源代码]#

设置一个精灵的命中盒。点击框应该相对于精灵的中心,并且比例应为1.0。将使用GET_ADJUST_HIT_BOX缩放点。

set_position(center_x: float, center_y: float)[源代码]#

设置精灵的位置

参数
  • center_x (float) -- 精灵的新x位置

  • center_y (float) -- 精灵的新y位置

set_texture(texture_no: int)[源代码]#

按纹理ID设置纹理。应该重命名,因为它接受一个数字而不是纹理,但为了向后兼容而保留这个名称。

stop()[源代码]#

停止Sprite的运动。

strafe(speed: float = 1.0)[源代码]#

横向调整精灵的移动向量。此方法并不实际移动精灵,只是获取当前的change_x/change_y并按给定的速度进行调整。

参数

speed -- 速度系数

property top: float#

返回精灵顶部的y坐标。

turn_left(theta: float = 90.0)[源代码]#

将精灵向左旋转传递度数。

参数

theta -- 角度的变化,以度为单位

turn_right(theta: float = 90.0)[源代码]#

将精灵向右旋转传递的度数。

参数

theta -- 角度的变化,以度为单位

update()[源代码]#

更新子画面。

update_animation(delta_time: float = 0.016666666666666666)[源代码]#

覆盖此选项以添加将更改显示的图像的代码,以便可以为精灵设置动画。

参数

delta_time (float) -- 自上次更新以来的时间。

property visible: bool#

获取或设置此子画面的可见性。这是将精灵的Alpha值更改为0或255的快捷方式:

# Make the sprite invisible
sprite.visible = False
# Change back to visible
sprite.visible = True
# Toggle visible
sprite.visible = not sprite.visible
返回类型

bool

property width: float#

获取精灵的宽度。

arcade.SpriteCircle#

class arcade.SpriteCircle(radius: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], soft: bool = False)[源代码]#

这个精灵只是一个纯色的椭圆形精灵。不需要使用图像文件。

参数
  • radius (float) -- 圆的半径

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

  • soft (bool) -- 如果为True,将添加Alpha渐变

arcade.SpriteSolidColor#

class arcade.SpriteSolidColor(width: int, height: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[源代码]#

这个精灵只是一个纯色的长方形精灵。不需要使用图像文件。

参数
  • width (int) -- 精灵的宽度

  • height (int) -- 精灵的高度

  • color (Color) -- 精灵的颜色

arcade.get_distance_between_sprites#

arcade.get_distance_between_sprites(sprite1: arcade.sprite.Sprite, sprite2: arcade.sprite.Sprite) float[源代码]#

返回两个给定子画面中心之间的距离

参数
  • sprite1 (Sprite) -- Sprite一号

  • sprite2 (Sprite) -- 两杯Sprite

返回

距离

返回类型

float

arcade.load_animated_gif#

arcade.load_animated_gif(resource_name)[源代码]#

给定一个动画gif,返回一个AnimatedTimeBasedSprite。

在Python中缺乏对动画gif中的透明度的支持。有很多更老的动画gif保存得很奇怪。最终的结果是,动画gif的第一帧通常是唯一正确获得透明度的帧。在Pillow库更好地处理这一问题之前,加载动画gif将会非常麻烦。