Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
- `anchor_x="center"` cut off the left half of the text, and `anchor_x="right"` made an empty sprite.
- The sprite was placed too high. It now covers the same area as an `arcade.Text` with the same arguments at the same position.
- An empty string raised `ValueError`. It now makes a transparent sprite, as documented.
- Text sprites went blank when the texture atlas rebuilt itself, which happens when it fills up after some textures were freed. The atlas redraws textures from their images, and a text sprite's image was empty. `sprite.texture.image` now also contains the text.

### New Features
- Added `arcade.sweep_sprite(sprite, dx, dy, sprite_list)`, which checks the whole path of a moving sprite and returns a `SweepInfo` for the first sprite it would hit (the `sprite`, how far along the move as a `fraction` and `distance`, and the surface `normal`), or `None`. Fast sprites can't pass through thin walls this way. A sprite that already overlaps one is an immediate hit. Added the `sprite_bullets_sweep` example comparing it with a plain collision check.
Expand Down
4 changes: 4 additions & 0 deletions arcade/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,10 @@ def create_text_sprite(
with texture_atlas.render_into(texture) as fbo:
fbo.clear(color=background_color or arcade.color.TRANSPARENT_BLACK)
text_object.draw()
# Keep a copy of the pixels in the texture's image. The atlas redraws
# textures from their images when it rebuilds itself, which would
# otherwise leave the sprite blank.
texture_atlas.update_texture_image_from_atlas(texture)

# Place the sprite where the Text object was drawn
return arcade.Sprite(
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/text/test_text_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def test_same_text_different_style(window):
assert red[1] > 200 and blue[1] == 0


def test_survives_atlas_rebuild(window):
"""The text is kept when the atlas rebuilds itself from the textures' images"""
atlas = window.ctx.default_atlas
sprite = arcade.create_text_sprite("Hello World", color=arcade.color.RED, font_size=20)
image = atlas.read_texture_image_from_atlas(sprite.texture)
assert _ink(image) > 0
# The texture's own image has the text too
assert sprite.texture.image.tobytes() == image.tobytes()

atlas.rebuild()
assert atlas.read_texture_image_from_atlas(sprite.texture).tobytes() == image.tobytes()


def test_empty_text(window):
"""An empty string makes a transparent sprite instead of failing"""
sprite = arcade.create_text_sprite("")
Expand Down
Loading