Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/foxcapades/renpy-spritesheet-animation

Demonstration and source for generating animations from sprite sheets.
https://github.com/foxcapades/renpy-spritesheet-animation

animation renpy spritesheet

Last synced: 5 days ago
JSON representation

Demonstration and source for generating animations from sprite sheets.

Awesome Lists containing this project

README

        

= Animations from Sprite Sheets
:source-highlighter: highlight.js

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

[source, python]
----
image explosion = spritesheet_animation("images/explosion.png", 8, 6)
----

[IMPORTANT]
--
Requires Ren'Py 8.3+
--

== 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
--
[cols="1m,1m,8"]
|===

| 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
--
[cols="1m,1m,8"]
|===

| 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

. This function does not allow the creation of animations with different pause
times between frames. For example replicating the following is not possible:
+
[source, python]
----
image foobar:
"frame01"
pause 0.1
"frame02"
pause 0.2
"frame03"
pause 0.3
----
. 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

* `__get_image_size` adapted from an answer on
link:https://stackoverflow.com/a/20380514[this StackOverflow question].
* `explosion.png` from https://www.pngegg.com/en/png-nvowz

== License

Published under the link:license[MIT License] which practically says "go nuts,
use it however you want."