[docs]defload_animated_gif(resource_name)->TextureAnimationSprite:""" Attempt to load an animated GIF as an :class:`TextureAnimationSprite`. Many older GIFs will load with incorrect transparency for every frame but the first. Until the Pillow library handles the quirks of the format better, loading animated GIFs will be pretty buggy. A good workaround is loading GIFs in another program and exporting them as PNGs, either as sprite sheets or a frame per file. """file_name=resolve(resource_name)image_object=PIL.Image.open(file_name)ifnotimage_object.is_animated:raiseTypeError(f"The file {resource_name} is not an animated gif.")sprite=TextureAnimationSprite()keyframes=[]forframeinrange(image_object.n_frames):image_object.seek(frame)frame_duration=image_object.info['duration']image=image_object.convert("RGBA")texture=Texture(image)texture.file_path=file_name# sprite.textures.append(texture)keyframes.append(TextureKeyframe(texture,frame_duration))animation=TextureAnimation(keyframes=keyframes)sprite.animation=animationreturnsprite