@@ -108,22 +108,30 @@ class FadeTransition:
108
108
109
109
switcher.switch_to(next_scene, FadeTransition())
110
110
'''
111
- def __init__ (self , * , overlay_color = 'black' , out_duration = 300 , in_duration = 300 , interval = 100 ):
111
+ def __init__ (self , * , overlay_color = 'black' , overlay_image = None , out_duration = 300 , in_duration = 300 , interval = 100 ):
112
112
'''
113
+ :param overlay_image: If specified, this image will be used instead of the ``overlay_color``.
113
114
:param out_duration: The duration of the fadeout animation.
114
115
:param in_duration: The duration of the fadein animation.
115
116
:param interval: The interval between the fadeout animation and the fadein animation.
117
+
118
+ .. versionchanged:: 0.2.0
119
+ Added the ``overlay_image`` parameter.
116
120
'''
117
- self .overlay_color = overlay_color
121
+ self ._overlay_color = overlay_color
122
+ self ._overlay_image = overlay_image
118
123
self .out_duration = out_duration
119
124
self .in_duration = in_duration
120
125
self .interval = interval
121
126
122
127
async def __call__ (self , * , priority , draw_target , clock , executor , ** kwargs ):
123
- overlay_surface = draw_target .copy ()
124
- overlay_surface .fill (self .overlay_color )
125
- set_alpha = overlay_surface .set_alpha
126
- with executor .register (partial (draw_target .blit , overlay_surface ), priority = priority ):
128
+ if (img := self ._overlay_image ) is None :
129
+ img = draw_target .copy ()
130
+ img .fill (self ._overlay_color )
131
+ self ._overlay_image = img
132
+ set_alpha = img .set_alpha
133
+ target_center = draw_target .get_rect ().center
134
+ with executor .register (partial (draw_target .blit , img , img .get_rect (center = target_center )), priority = priority ):
127
135
async for v in clock .interpolate (0 , 255 , duration = self .out_duration ):
128
136
set_alpha (v )
129
137
yield
0 commit comments