Skip to content

Commit aa5b5b0

Browse files
committed
Add tests for BasicSprite / Sprite .rgb property
1 parent 5a5abb0 commit aa5b5b0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/unit/sprite/test_sprite.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,44 @@ def test_visible():
336336
assert sprite.alpha == 100
337337

338338

339+
def test_sprite_rgb_property():
340+
sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png")
341+
342+
# Initial multiply tint is white
343+
assert sprite.rgb == (255, 255, 255)
344+
345+
# Test color setting + .rgb report when .visible == True
346+
sprite.rgb = (1, 3, 5, 7)
347+
assert sprite.color.r == 1
348+
assert sprite.color.g == 3
349+
assert sprite.color.b == 5
350+
assert sprite.rgb[0] == 1
351+
assert sprite.rgb[1] == 3
352+
assert sprite.rgb[2] == 5
353+
354+
# Test alpha preservation
355+
assert sprite.color.a == 255
356+
assert sprite.alpha == 255
357+
358+
# Test .rgb sets rgb chanels when visible == False as with .color,
359+
# but also still preserves original alpha values.
360+
sprite.visible = False
361+
sprite.color = (9, 11, 13, 15)
362+
sprite.rgb = (17, 21, 23, 25)
363+
364+
# Check the color channels
365+
assert sprite.color.r == 17
366+
assert sprite.color.g == 21
367+
assert sprite.color.b == 23
368+
assert sprite.rgb[0] == 17
369+
assert sprite.rgb[1] == 21
370+
assert sprite.rgb[2] == 23
371+
372+
# Alpha preserved?
373+
assert sprite.color.a == 15
374+
assert sprite.alpha == 15
375+
376+
339377
def test_sprite_scale_xy(window):
340378
sprite = arcade.SpriteSolidColor(20, 20, color=arcade.color.WHITE)
341379

0 commit comments

Comments
 (0)