diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 80f95d427..5d7ac17f8 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -958,7 +958,7 @@ def draw(self, *, filter=None, pixelated=None, blend_function=None): :param blend_function: Optional parameter to set the OpenGL blend function used for drawing the sprite list, such as 'arcade.Window.ctx.BLEND_ADDITIVE' or 'arcade.Window.ctx.BLEND_DEFAULT' """ - if len(self.sprite_list) == 0 or not self._visible: + if len(self.sprite_list) == 0 or not self._visible or self.alpha_normalized == 0.0: return self._init_deferred() diff --git a/tests/unit/spritelist/test_spritelist_draw.py b/tests/unit/spritelist/test_spritelist_draw.py new file mode 100644 index 000000000..c19cbcd19 --- /dev/null +++ b/tests/unit/spritelist/test_spritelist_draw.py @@ -0,0 +1,30 @@ +import pytest +import arcade +from arcade.gl import Geometry + + +def test_visible(window, monkeypatch): + """Ensure invisible spritelists are not drawn""" + sp = arcade.SpriteList() + # Monkeypatch Geometry.render to raise an error if called + def mock_draw(*args, **kwargs): + raise AssertionError("Should not be called") + monkeypatch.setattr(Geometry, "render", mock_draw) + + # Empty spritelist should not be rendered + sp.draw() + + # It will draw if it has sprites + sp.append(arcade.SpriteSolidColor(10, 10, color=arcade.color.RED)) + # Geometry.render should be called + with pytest.raises(AssertionError): + sp.draw() + + # Invisible should not be rendered + sp.visible = False + sp.draw() + sp.visible = True + + # Alpha 0 should not be rendered + sp.alpha = 0 + sp.draw()