Page 1 of 1
Keeping a Character Tag Consistent for Layered Sprites
Posted: Fri Oct 09, 2020 7:34 pm
by Aiyuu
I've been looking around to see if I can find a solution for what I would assume should be a simple question, but I don't even know where to begin when it seems every answer I've found is apt for things that are much more complicated than what I'm trying to achieve, so I'm hardly sure what to even put in the code as a test.
In short, I have at least 2 poses per character, and every expression is tied to a specific pose. I want to optimize the total file size of my project by creating base images for poses and additional images for expressions which display at the same time as the base images. It seems ridiculous to need to call a specific pose while also calling an expression even though the two are inseparable and not interchangeable, so ideally, here is what I would want:
Let's say there are 6 images:
•x_pose1.png
•x_happy.png (tied to pose 1)
•x_content.png (tied to pose 1)
•x_pose2.png
•x_surprised.png (tied to pose 2)
•x_angry.png (tied to pose 2)
This character has no alternate appearances, so I would need to group the images accordingly while making each base+expression called and replaced by one tag. If that tag is "X", then...
...should display "x_happy.png" over "x_pose1.png", and then...
...should replace both of the previously shown images with "x_surprised.png" over "x_pose2.png".
If I want to do this without typing a billion "layeredimage ___:" statements for every expression, what should my code look like?
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 12:24 am
by Jackkel Dragon
For some reason I feel like there is a better way to name the files to make this easier to do, but going off the filenames as-is I'd probably do something like this:
Code: Select all
layeredimage x:
group face:
attribute happy default:
"x_happy"
attribute content:
"x_content"
attribute surprised:
"x_surprised"
attribute angry:
"x_angry"
group body
group body variant "pose1" if_any ["happy","content"]:
"x_pose1"
group body variant "pose2" if_any ["surprised", "angry"]:
"x_pose2"
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 2:06 pm
by Aiyuu
The file names are placeholders not reflective of the final product and there only for demonstration. But otherwise, trying that code gives me the "expected statement" error right after "layeredimage x:", so I have no idea what the problem is there.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 2:31 pm
by Jackkel Dragon
What does the error say exactly? The best I can think of is that maybe my sample code needs to have something after "group body". In the portrait code I'm using for my game, I have:
Therefore, it's not an empty block after "group body". Maybe see if leaving out that line helps. (I just figured you needed to define a group before defining variants, but I'm not certain how Ren'Py handles those.)
Edit: At any rate, here's one way I might write this if I had filenames that were set up with layeredimage's auto images in mind:
Code: Select all
layeredimage x:
group face auto:
attribute happy default
#group body: ## is this needed?
## block here?
group body variant "pose1" if_any ["happy","content"]: ## if set as auto, would the filename be "x_body_pose1_[attribute]"?
"x_pose1"
group body variant "pose2" if_any ["surprised", "angry"]:
"x_pose2"
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 2:53 pm
by Aiyuu
The error says:
Code: Select all
File "game/setup.rpy", line 98: expected statement.
layeredimage x:
^
Ren'Py Version: Ren'Py 6.99.12.3.2123
Adding that extra part after "group body" doesn't change or update the error in any way.
EDIT: I just saw your edit after posting, so I'll take a look at that momentarily.
EDIT: Once again, that's the only currently visible error.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 3:04 pm
by Jackkel Dragon
The only thing I can think of without seeing the code is that there might be an indentation problem or something. Is this within a python block or a Ren'Py label? As far as I know, layered images need to be in the top context/namespace. For instance:
Code: Select all
S 1 2
[line start]
[indent level 1]
python:
x = 5
label start:
"start the game"
$ end = True
if (end):
"end the game"
layeredimage x:
"x_all"
image y = "images/y.png"
label make_images:
#image z = "z.png" ## this would be an "unexpected statement" within the Ren'Py label context
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 3:19 pm
by Aiyuu
The section is not within a label. The first line ("layeredimage x:") remains un-indented in the same .rpy file I've used for other image defines.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 3:57 pm
by Jackkel Dragon
I finally sat down and tried to make Ren'Py compile the sample myself, and I figured out at least one part of the problem. It seems I forgot to define the attributes for the body layer:
Code: Select all
layeredimage x:
group face auto:
attribute happy default
group body variant "pose1" if_any ["happy","content"]:
attribute body default:
"x_pose1"
group body variant "pose2" if_any ["surprised", "angry"]:
attribute body default:
"x_pose2"
This compiles and runs for me, though I don't know if it looks the way you want it to just yet. It should, based on my understanding of "if_any", but it would be a good idea to test it with real images.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 4:07 pm
by Aiyuu
Copying and pasting that code as-is returns an identical error, so I'm hardly sure what else to input. This is almost making me suspect that this particular formatting might not be compatible with the version of Ren'Py I'm using. However, since you mention images, and since there are no file paths specified in that code, that does make me wonder how it would even find the particular folder in which the sprites are stored.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 4:30 pm
by Jackkel Dragon
One, what version of Ren'Py are you using? I'm starting to wonder if this version even has layered image support.
Two, does your version of Ren'Py not have an images folder that can auto-define images? Auto-defined images from the image folder are a massive part of making layered images without needing to create every attribute for every file manually.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 4:39 pm
by Aiyuu
The version is 6.99.12.3.2123.
There is an "images" folder, which apparently does identify images automatically without a file path prefix, as I just checked. I might have had a separate problem with that a long time ago, so I assumed the file path was a necessity.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 7:41 pm
by Jackkel Dragon
That explains things: layered images were added in Ren'Py 7.0. You will need to update Ren'Py in order to use them.
Re: Keeping a Character Tag Consistent for Layered Sprites
Posted: Sat Oct 10, 2020 10:26 pm
by Aiyuu
I got around to updating to the latest version, and the last code you provided no longer causes the game to crash, so that's a step in the right direction. However, it seems that while the base ("body") images appear normally, the corresponding expressions don't appear.