[Solved] How to change alpha on layeredimage as a whole image?

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
arewar
Newbie
Posts: 9
Joined: Wed Feb 09, 2022 1:37 pm
Projects: https://arewar.itch.io/particles-of-reality
Tumblr: arewar
itch: arewar
Discord: jadegodsey
Contact:

[Solved] How to change alpha on layeredimage as a whole image?

#1 Post by arewar »

I have a sprite that's a layered image, with separate attributes for facial expressions (which works great). Ex.

Code: Select all

layeredimage cSebastian:
    always:
        "characterLayerSprites/sebastian/body.png"
    group eyes:
        attribute cry:
            "characterLayerSprites/sebastian/eyesCry.png"
        attribute normal default:
            "characterLayerSprites/sebastian/eyesNeutral.png"
    group mouth:
        attribute frown:
            "characterLayerSprites/mouth/frown.png"
        attribute neutral default:
            "characterLayerSprites/mouth/neutral.png"
In my scene, when I run the code...

Code: Select all

show cSebastian:
     alpha 0.5
The game is changing the alpha of each layer, not the image as a whole. This means I can see the skull of my character through his hair.


I've found https://www.renpy.org/doc/html/displaya ... rm#Flatten, but how do I use it? I can't find any examples.

Some things I've tried:

A python function

Code: Select all

init python:
    def flatIt(chr):
        return renpy.display.layout.Flatten(chr)
$ newVar = flatIt(cSebastian)
show newVar
A transform

Code: Select all

transform flat(chr):
        Flatten(chr)
show cSebastian at flat(testSebastian)
Straight command:

Code: Select all

show renpy.display.layout.Flatten(cSebastian)
Everything I've tried has either given me errors like cSebastian is not a displayable, not defined, or just shows that gray empty character girl.

I've also considered adding the sprite to a new custom layer, but I couldn't figure out how to change the alpha of a layer.

Could someone show me a working example of how to get a LayerImage Sprite to be partially transparent as a whole image? I don't mind if it's using a different method than flatten.
Last edited by arewar on Wed Mar 02, 2022 11:27 am, edited 1 time in total.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: How to change alpha on layeredimage as a whole image?

#2 Post by emz911 »

Try defining the image as a layered image proxy, then give it an alpha transform.

Code: Select all

layeredimage cSebastian:
  ...
image cSebastian_temp = LayeredImageProxy("cSebastian", Transform(alpha=0.5))

label start:
     show cSebastian_temp # or whatever you rename it to
If you want to use it with different transforms, not only for alpha, maybe take out the Transform in the define and make it a simple LayeredImageProxy, applying transforms when you show image

User avatar
arewar
Newbie
Posts: 9
Joined: Wed Feb 09, 2022 1:37 pm
Projects: https://arewar.itch.io/particles-of-reality
Tumblr: arewar
itch: arewar
Discord: jadegodsey
Contact:

Re: How to change alpha on layeredimage as a whole image?

#3 Post by arewar »

Thanks for the suggestion, but that gives me the same result. I can see the skull through the character's hair.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: How to change alpha on layeredimage as a whole image?

#4 Post by emz911 »

Okay, looking at the link you've posted, flatten seems like it could work. It's under displayables, meaning you should define it like defining any other image displayable. Haven't tried it out yet, but it should be something close to:

Code: Select all

image cSebastian_flat = Flatten("cSebastian", Transform(alpha=0.5))

If referencing the layered image directly doesn't work, try proxying again:

image cSebastian_flat = Flatten(LayeredImageProxy("cSebastian"), Transform(alpha=0.5))

User avatar
arewar
Newbie
Posts: 9
Joined: Wed Feb 09, 2022 1:37 pm
Projects: https://arewar.itch.io/particles-of-reality
Tumblr: arewar
itch: arewar
Discord: jadegodsey
Contact:

Re: How to change alpha on layeredimage as a whole image?

#5 Post by arewar »

Sorry for the delay!

Your suggestion kind-of works, it does give me a flat transparent image, but not like I hoped to use it.

This is how I hoped it would work, but I get errors "image cSebastian_flat does not accept attributes glare yell".

Code: Select all

image cSebastian_flat = Flatten("cSebastian")
show cSebastian_flat glare yell
This does work, but that means I would have to declare a separate image for every facial expression combination I wanted to use.

Code: Select all

image cSebastian_flat = Flatten("cSebastian glare")
show cSebastian_flat
And trying to do it without declaration does not work. I get the empty girl silhouette.

Code: Select all

show Flatten("cSebastian")
Is what I am trying to achieve not possible?

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: How to change alpha on layeredimage as a whole image?

#6 Post by emz911 »

emz911 wrote: Sun Feb 27, 2022 3:30 pm

Code: Select all

If referencing the layered image directly doesn't work, try proxying again:

image cSebastian_flat = Flatten(LayeredImageProxy("cSebastian"), Transform(alpha=0.5))
Hmm.. Did you try the second option, defining it with a layered image proxy yet?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to change alpha on layeredimage as a whole image?

#7 Post by Remix »

Try

Code: Select all

show cSebastian:
    mesh True
    alpha 0.5
Frameworks & Scriptlets:

User avatar
arewar
Newbie
Posts: 9
Joined: Wed Feb 09, 2022 1:37 pm
Projects: https://arewar.itch.io/particles-of-reality
Tumblr: arewar
itch: arewar
Discord: jadegodsey
Contact:

Re: How to change alpha on layeredimage as a whole image?

#8 Post by arewar »

Remix, thank you!!! "mesh True" worked!

For flattening the proxy, that threw an error.
image cSebastian2_flat = Flatten(LayeredImageProxy("cSebastian"))
# AttributeError: 'LayeredImageProxy' object has no attribute '_duplicatable'

Thank you both so much for your help.

User avatar
Rex Nihilo
Newbie
Posts: 4
Joined: Sat Jan 18, 2020 10:20 am
Projects: Dig My Way
Tumblr: nihilorex
Deviantart: nihilorex
Github: rex-nihilo
Location: Third Stone from the Sun
Contact:

Re: [Solved] How to change alpha on layeredimage as a whole image?

#9 Post by Rex Nihilo »

To flatten the proxy character and apply transparency:

Code: Select all

image cSebastian_flat = LayeredImageProxy("cSebastian", Transform(mesh=True, alpha=0.5))

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]