11import array
2+ from typing import Optional
23
34from arcade import gl
45from arcade .color import WHITE
56from arcade .math import rotate_point
67from arcade .sprite import BasicSprite
78from arcade .texture import Texture
9+ from arcade .texture_atlas .base import TextureAtlasBase
810from arcade .types import LBWH , LRBT , RGBA255 , XYWH , Color , PointList , Rect
911from arcade .window_commands import get_window
1012
@@ -20,6 +22,7 @@ def draw_texture_rect(
2022 blend = True ,
2123 alpha = 1.0 ,
2224 pixelated = False ,
25+ atlas : Optional [TextureAtlasBase ] = None ,
2326) -> None :
2427 """
2528 Draw a texture on a rectangle.
@@ -30,6 +33,7 @@ def draw_texture_rect(
3033 :param angle: Rotation of the texture in degrees. Defaults to zero.
3134 :param blend: If True, enable alpha blending. Defaults to True.
3235 :param alpha: Transparency of image. 0.0 is fully transparent, 1.0 (default) is visible.
36+ :param atlas: The texture atlas the texture resides in. if not supplied the default texture atlas is used
3337 """
3438 ctx = get_window ().ctx
3539
@@ -38,9 +42,9 @@ def draw_texture_rect(
3842 else :
3943 ctx .disable (ctx .BLEND )
4044
41- atlas = ctx .default_atlas
45+ atlas = atlas or ctx .default_atlas
4246
43- texture_id , _ = ctx . default_atlas .add (texture )
47+ texture_id , _ = atlas .add (texture )
4448 if pixelated :
4549 atlas .texture .filter = gl .NEAREST , gl .NEAREST
4650 else :
@@ -64,11 +68,22 @@ def draw_texture_rect(
6468 ctx .disable (ctx .BLEND )
6569
6670
67- def draw_sprite (sprite : BasicSprite , * , blend : bool = True , alpha = 1.0 , pixelated = False ) -> None :
71+ def draw_sprite (
72+ sprite : BasicSprite ,
73+ * ,
74+ blend : bool = True ,
75+ alpha = 1.0 ,
76+ pixelated = False ,
77+ atlas : Optional [TextureAtlasBase ] = None ,
78+ ) -> None :
6879 """
6980 Draw a sprite.
7081
7182 :param sprite: The sprite to draw.
83+ :param blend: Draw the sprite with or without alpha blending
84+ :param alpha: Fade the sprite from completely transparent to opaque (range: 0.0 to 1.0)
85+ :param pixelated: If true the sprite will be render in pixelated style. Otherwise smooth/linear
86+ :param atlas: The texture atlas the texture resides in. if not supplied the default texture atlas is used
7287 """
7388 draw_texture_rect (
7489 sprite .texture ,
@@ -78,16 +93,28 @@ def draw_sprite(sprite: BasicSprite, *, blend: bool = True, alpha=1.0, pixelated
7893 blend = blend ,
7994 alpha = alpha ,
8095 pixelated = pixelated ,
96+ atlas = atlas ,
8197 )
8298
8399
84100def draw_sprite_rect (
85- sprite : BasicSprite , rect : Rect , * , blend : bool = True , alpha = 1.0 , pixelated = False
101+ sprite : BasicSprite ,
102+ rect : Rect ,
103+ * ,
104+ blend : bool = True ,
105+ alpha = 1.0 ,
106+ pixelated = False ,
107+ atlas : Optional [TextureAtlasBase ] = None ,
86108) -> None :
87109 """
88110 Draw a sprite.
89111
90112 :param sprite: The sprite to draw.
113+ :param rect: The location and size of the sprite
114+ :param blend: Draw the sprite with or without alpha blending
115+ :param alpha: Fade the sprite from completely transparent to opaque (range: 0.0 to 1.0)
116+ :param pixelated: If true the sprite will be render in pixelated style. Otherwise smooth/linear
117+ :param atlas: The texture atlas the texture resides in. if not supplied the default texture atlas is used
91118 """
92119 draw_texture_rect (
93120 sprite .texture ,
@@ -97,6 +124,7 @@ def draw_sprite_rect(
97124 blend = blend ,
98125 alpha = alpha ,
99126 pixelated = pixelated ,
127+ atlas = atlas ,
100128 )
101129
102130
0 commit comments