Text - Image/Pillow based#
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 [source]#
Create a PIL.Image containing text.
Warning
This method can be fairly slow. We recommend creating images on initialization or infrequently later on.
- Parameters
text (str) – The text to render to the image
text_color (Color) – Color of the text
font_size (float) – Size of the font
width (int) – The width of the image in pixels
align (str) – “left” or “right” aligned
valign (str) – “top” or “bottom” aligned
font_name (str) – The font to use
background_color (Color) – The background color of the image
height (int) – the height of the image in pixels
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 [source]#
Creates a sprite with a text texture using
create_text_image()
.Internally this works by creating an image, and using the Pillow library to draw the text to it. Then use that image to create a sprite. We cache the sprite (so we don’t have to recreate over and over, which is slow) and use it to draw text to the screen.
This implementation does not support bold/italic like the older Pyglet-based implementation of draw_text. However if you specify the ‘italic’ or ‘bold’ version of the font via the font name, you will get that font. Just the booleans do not work.
- Parameters
text (str) – Text to draw
start_x (float) – x coordinate of the lower-left point to start drawing text
start_y (float) – y coordinate of the lower-left point to start drawing text
color (Color) – Color of the text
font_size (float) – Size of the text
width (float) – Width of the text-box for the text to go into. Used with alignment.
align (str) – Align left, right, center
font_name (Union[str, Tuple[str, ...]]) – Font name, or list of font names in order of preference
bold (bool) – Bold the font (currently unsupported)
italic (bool) – Italicize the font (currently unsupported)
anchor_x (str) – Anchor the font location, defaults to ‘left’
anchor_y (str) – Anchor the font location, defaults to ‘baseline’
rotation (float) – Rotate the text