arcade
arcade copied to clipboard
Lift the atlas restriction on create_text_sprite
Enhancement request:
What should be added/changed?
The function create_text_sprite (and, if https://github.com/pythonarcade/arcade/issues/1410 is resolved, create_text_texture) requires a TextureAtlas since the text texture is created by rendering into it. This adds the restriction (as explained in the docstring) that the Sprite/Texture can only be used with that one TextureAtlas. Normally, one does not need an atlas to create a texture nor a sprite, and a texture can be put in multiple texture atlases, and a sprite in multiple spritelists. Therefore, this restriction imposed by the function(s) stands out and breaks common use cases.
What would it help with?
Users can create text textures and text sprites without needing a texture atlas first. They can then be used with multiple atlases/spritelists.
I tried something really simple, just create a new image from a texture atlas and then a new texture from that image, and it seems to work. Not sure about performance/elegance etc, but as a proof of concept it definitely works:
texture = arcade.Texture.create_empty(text, size)
texture_atlas = arcade.TextureAtlas.create_from_texture_sequence([texture])
with texture_atlas.render_into(texture) as fbo:
fbo.clear((0, 0, 0, 0))
_draw_pyglet_label(_label)
return arcade.Texture(image=texture_atlas.get_texture_image(texture))