Skip to content

Improve text sprite background color #1956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ def create_text_sprite(
anchor_x: str = "left",
multiline: bool = False,
texture_atlas: Optional[arcade.TextureAtlas] = None,
background_color: Optional[RGBA255] = None,
) -> arcade.Sprite:
"""
Creates a sprite containing text based off of :py:class:`~arcade.Text`.
Expand Down Expand Up @@ -623,6 +624,8 @@ def create_text_sprite(
:param multiline: Requires width to be set; enables word wrap rather than clipping
:param texture_atlas: The texture atlas to use for the
newly created texture. The default global atlas will be used if this is None.
:param background_color: The background color of the text. If None, the background
will be transparent.
"""
text_object = Text(
text,
Expand Down Expand Up @@ -651,7 +654,7 @@ def create_text_sprite(
texture_atlas = arcade.get_window().ctx.default_atlas
texture_atlas.add(texture)
with texture_atlas.render_into(texture) as fbo:
fbo.clear((0, 0, 0, 255))
fbo.clear(background_color or arcade.color.TRANSPARENT_BLACK)
text_object.draw()

return arcade.Sprite(
Expand Down