Keeping a Character Tag Consistent for Layered Sprites

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Keeping a Character Tag Consistent for Layered Sprites

#1 Post 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...

Code: Select all

show X happy
...should display "x_happy.png" over "x_pose1.png", and then...

Code: Select all

show X surprised
...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?

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#2 Post 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"
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#3 Post 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.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#4 Post 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:

Code: Select all

group body:
	zoom 0.5
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"
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#5 Post 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.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#6 Post 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
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#7 Post 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.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#8 Post 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.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#9 Post 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.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#10 Post 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.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#11 Post 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.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#12 Post 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.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Aiyuu
Regular
Posts: 28
Joined: Thu Aug 02, 2018 7:58 pm
Completed: Ovine Replica
Projects: Ovine Replica, Ursine Science
itch: amorous-ursidae
Contact:

Re: Keeping a Character Tag Consistent for Layered Sprites

#13 Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]