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
16 changes: 14 additions & 2 deletions arcade/sprite/colored.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,24 @@ class SpriteCircle(Sprite):
soft:
If ``True``, the circle will fade from an opaque
center to transparent edges.
center_x:
Initial x position of the sprite
center_y:
Initial y position of the sprite
"""

# Local weak cache for textures to avoid creating multiple instances with the same configuration
_texture_cache: WeakValueDictionary[tuple[int, RGBA255, bool], Texture] = WeakValueDictionary()

def __init__(self, radius: int, color: RGBA255, soft: bool = False, **kwargs):
def __init__(
self,
radius: int,
color: RGBA255,
soft: bool = False,
center_x: float = 0,
center_y: float = 0,
**kwargs,
):
radius = int(radius)
diameter = radius * 2

Expand All @@ -168,5 +180,5 @@ def __init__(self, radius: int, color: RGBA255, soft: bool = False, **kwargs):
self.__class__._texture_cache[cache_key] = texture

# apply results to the new sprite
super().__init__(texture)
super().__init__(texture, center_x=center_x, center_y=center_y)
self.color = Color.from_iterable(color)
4 changes: 3 additions & 1 deletion tests/unit/sprite/test_sprite_colored.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

def test_sprite_circle_props():
"""Test basic properties of SpriteCircle"""
sprite = arcade.SpriteCircle(50, arcade.color.RED)
sprite = arcade.SpriteCircle(50, arcade.color.RED, center_x=5, center_y=7)
assert sprite.color == arcade.color.RED
assert sprite.size == (100, 100)
assert sprite.center_x == 5
assert sprite.center_y == 7


def test_sprite_circle_texture_cache():
Expand Down
Loading