基于文本-图像/枕头#

arcade.create_text_image#

arcade.create_text_image(text: str, text_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 0, align: str = 'left', valign: str = 'top', font_name: Union[str, Tuple[str, ...]] = ('calibri', 'arial'), background_color: Optional[Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]] = None, height: int = 0) PIL.Image.Image[源代码]#

创建一个PIL。包含文本的图像。

警告

这种方法可能相当慢。我们建议在初始化时或以后不频繁地创建映像。

参数
  • text (str) -- 要呈现到图像的文本

  • text_color (Color) -- 文本的颜色

  • font_size (float) -- 字体大小

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

  • align (str) -- “左”或“右”对齐

  • valign (str) -- “顶部”或“底部”对齐

  • font_name (str) -- 要使用的字体

  • background_color (Color) -- 图像的背景色

  • height (int) -- 以像素为单位的图像高度

arcade.create_text_sprite#

arcade.create_text_sprite(text: str, start_x: float, start_y: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 0, align: str = 'left', font_name: Union[str, Tuple[str, ...]] = ('calibri', 'arial'), bold: bool = False, italic: bool = False, anchor_x: str = 'left', anchor_y: str = 'baseline', rotation: float = 0) arcade.sprite.Sprite[源代码]#

使用创建具有文本纹理的精灵 create_text_image()

在内部,这是通过创建一个图像并使用Pillow库将文本绘制到该图像来实现的。然后使用该图像创建一个精灵。我们缓存精灵(这样我们就不必一遍又一遍地重新创建,这很慢),并使用它将文本绘制到屏幕上。

该实现不支持粗体/斜体,不像以前的基于Pyglet的DRAW_TEXT实现那样。但是,如果您通过字体名称指定字体的‘斜体’或‘粗体’版本,您将获得该字体。只有布尔人是行不通的。

参数
  • text (str) -- 要绘制的文本

  • start_x (float) -- 开始绘制文本的左下点的X坐标

  • start_y (float) -- 开始绘制文本的左下点的Y坐标

  • color (Color) -- 文本的颜色

  • font_size (float) -- 文本大小

  • width (float) -- 文本要进入的文本框的宽度。与对齐一起使用。

  • align (str) -- 左、右、中对齐

  • font_name (Union[str, Tuple[str, ...]]) -- 字体名称,或按首选顺序排列的字体名称列表

  • bold (bool) -- 粗体字体(当前不受支持)

  • italic (bool) -- 将字体设置为斜体(当前不支持)

  • anchor_x (str) -- 固定字体位置,默认为‘Left’

  • anchor_y (str) -- 锚定字体位置,默认为‘Baseline’

  • rotation (float) -- 旋转文本