Automatic character, background, etc. image defining script
Posted: Sat Aug 02, 2014 10:17 pm
Below is a short script you can include in your project to automatically do all of your character image defining for you.
Contrary to the function name, it will also work for background images and such, though you might want to set flip to False for those.
You could also easily change this script to work with SFX, BGM, etc. but I haven't bothered since I don't have many right now.
For example, let's say I have a folder called "comms", and inside of that folder I have separate folders for each character, each character folder has different poses, etc.
I would include the above script and run:
This would tell the script to only include files in the "comm" folder, and to exclude the first one folder ("comm") from the definition.
So "comm/sara/schoolgirl/smiling.png" would become the image "sara schoolgirl smiling" (and "sara schoolgirl smiling flip").
While I'm at it, I could add another statement to define all of my backgrounds. eg.
There's no need for a script like this if you only have very few images.
But if your characters have several expressions, outfits, poses, etc. this can save you lots of define statements.
Rather than write statements like
etc.
you instead include the statement once and let your folder structure organize your images for you.
In my case, I have the folder structure of "comm" + artist + character + outfit + pose + expression.
So I include the statement define_characters("comm", 2), meaning characters are defined as character + outfit + pose + expression.
Since my characters mostly have >10 expressions, more than one pose, and more than one outfit, this saves me dozens of define statements per character, and I can add new poses, outfits, expressions, etc. without having to change the code at all.
*Note: any files in characterImageFolder will be processed, so you should have a dedicated folder for character images.
Don't include any text files, scripts, etc. in characterImageFolder.
Contrary to the function name, it will also work for background images and such, though you might want to set flip to False for those.
You could also easily change this script to work with SFX, BGM, etc. but I haven't bothered since I don't have many right now.
Code: Select all
init python:
import os
def define_characters(characterImageFolder, excludeFirstXFolders=0, flip=True):
for path in renpy.list_files():
if path.startswith(characterImageFolder + "/"):
path_list = path.split("/")
path_list[-1] = os.path.splitext(path_list[-1])[0]
path_list = tuple(path_list[excludeFirstXFolders:])
renpy.image(path_list, path)
if flip:
renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
I would include the above script and run:
Code: Select all
define_characters("comm", 1)
So "comm/sara/schoolgirl/smiling.png" would become the image "sara schoolgirl smiling" (and "sara schoolgirl smiling flip").
While I'm at it, I could add another statement to define all of my backgrounds. eg.
Code: Select all
define_characters("backgrounds", 1, False)
But if your characters have several expressions, outfits, poses, etc. this can save you lots of define statements.
Rather than write statements like
Code: Select all
image sara outfit1 pose1 expression1 = ...
image sara outfit1 pose1 expression2 = ...
...
image sara outfit3 pose2 expression12 = ...
you instead include the statement once and let your folder structure organize your images for you.
In my case, I have the folder structure of "comm" + artist + character + outfit + pose + expression.
So I include the statement define_characters("comm", 2), meaning characters are defined as character + outfit + pose + expression.
Since my characters mostly have >10 expressions, more than one pose, and more than one outfit, this saves me dozens of define statements per character, and I can add new poses, outfits, expressions, etc. without having to change the code at all.
*Note: any files in characterImageFolder will be processed, so you should have a dedicated folder for character images.
Don't include any text files, scripts, etc. in characterImageFolder.