Untitled

 avatar
unknown
plain_text
a year ago
1.3 kB
4
Indexable
    """
def init_animation_frames(file_name, frame_count):
    sprite_sheet_image = pygame.image.load(file_name).convert_alpha()   # load the image
    frame_width = sprite_sheet_image.get_width() / frame_count  # set the width of each frame by dividing the total width by the number of frames
    frame_height = sprite_sheet_image.get_height()  # get the height of the image
    animation_frames = []   # set up our frame list

    # loop for the number of frames in our image and fill up our frame list
    for frame in range(frame_count):
        # create a new surface for our image
        frame_surface = pygame.Surface((frame_width, frame_height)).convert_alpha()
        # set the background color that will be removed
        frame_surface.fill(BLUE)
        # draw the image onto the new surface, determining the loatation of the frame by frame number * frame width
        frame_surface.blit(sprite_sheet_image, (0, 0), ((frame * frame_width), 0, frame_width, frame_height))
        # the transparent part of the picture will be replaced with blue, so we need to set it back to transparent
        frame_surface.set_colorkey(BLUE)
        # add the new image to the end of the frame list
        animation_frames.append(frame_surface)

    return animation_frames
Editor is loading...
Leave a Comment