@@ -108,22 +108,30 @@ class FadeTransition:
108108
109109 switcher.switch_to(next_scene, FadeTransition())
110110 '''
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 ):
112112 '''
113+ :param overlay_image: If specified, this image will be used instead of the ``overlay_color``.
113114 :param out_duration: The duration of the fadeout animation.
114115 :param in_duration: The duration of the fadein animation.
115116 :param interval: The interval between the fadeout animation and the fadein animation.
117+
118+ .. versionchanged:: 0.2.0
119+ Added the ``overlay_image`` parameter.
116120 '''
117- self .overlay_color = overlay_color
121+ self ._overlay_color = overlay_color
122+ self ._overlay_image = overlay_image
118123 self .out_duration = out_duration
119124 self .in_duration = in_duration
120125 self .interval = interval
121126
122127 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 ):
127135 async for v in clock .interpolate (0 , 255 , duration = self .out_duration ):
128136 set_alpha (v )
129137 yield
0 commit comments