Skip to content

Foxcapades/renpy-spritesheet-animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Animations from Sprite Sheets

Source code for and a basic demonstration of generating animations based on png or jpg sprite sheet files.

image explosion = spritesheet_animation("images/explosion.png", 8, 6)

The spritesheet_animation Function

Generates an animation from the given sprite file path. The given path MUST be a valid path relative to the game directory including the file extension, e.g. "images/explosion.png".

This method supports the following file types: [ "png", "jpg" ]

Arguments

image_path

str

The path to the sprite sheet image file relative to the game directory. This path MUST include the file extension. Example: "images/explosion.png".

x_sprite_count

int

Number of sprites the sprite sheet has along the x-axis.

y_sprite_count

int

Number of sprites the sprite sheet has along the y-axis.

Keyword Arguments

fps

int|float

Frames per second for the animation. Incompatible with the pause keyword argument; setting both will cause an error. Defaults to 30.

pause

float

How long to pause between each frame. Incompatible with the fps keyword argument; setting both will cause an error. Defaults to None.

looping

bool

Whether the animation should loop. Defaults to False.

hold_last_frame

bool

Whether the animation should hold on the last frame or "vanish" after the last frame has played. Defaults to False (vanishing).

Caveats

  1. This function does not allow the creation of animations with different pause times between frames. For example replicating the following is not possible:

    image foobar:
        "frame01"
        pause 0.1
        "frame02"
        pause 0.2
        "frame03"
        pause 0.3
  2. All the sprites on the sprite sheet must be the same size, the function will divide the sprite sheet evenly by the given x_sprite_count and y_sprite_count values.

Credits

License

Published under the MIT License which practically says "go nuts, use it however you want."