[SOLVED] LiveComposite question

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
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

[SOLVED] LiveComposite question

#1 Post by yuren »

Hi folks. I am in stuck of something in live composite.

So I wanted to create a live composite image, where part of the image position can be changed depending on the condition. Consider this case:

I want to make a character , composed by the body and the hat. Now if the body size is small, of course I want the position of the hat to be adjusted also depending on the head positin.

I made a global variable named body size, and give the default value "big", let say.

Code: Select all

define body_size = "big"
and at the livecomposite, I write

Code: Select all


body = ConditionSwitch(...) # some if condition to switch between the body size value

image side char sample = LiveComposite(
    (317,600),
    (0, 0), body,
    hat_position(), "hat.png")

And I define function, named hat_position() like

Code: Select all

init python:
    def hat_position():
        global body_size
        if body_size == "big":
            return (200, 225)
        else:
            return (200, 155)
The interesting part is.. the body size variable always read as the default value, even though I change the value before the image is displayed. I came into this conclusion because if I change the compared value into the default value, it always return true, but if I change into other kind of value, it always return false

Note that the body size ConditionSwitch is working as expected. Which means the variable value is already changed, and also I checked on python console, typing the conditional value and it is working as expected.

Do I miss something here? I suspect that I misunderstood something quite fundamental..

Any helps is truly appreciated. Thanks!
Last edited by yuren on Tue Mar 22, 2016 9:37 am, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: LiveComposite question

#2 Post by xela »

Very weird use of a function... You prolly want to use another CS for that.
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: LiveComposite question

#3 Post by Onishion »

I think the problem is that a lot of bits about LCs are generated once at start-up, and can't be changed after that. Position might be one of those things. I think it's running your function once at start-up and never running it again, although I can't be sure about that. But yeah, like Xela was saying, it might be better to instead use condition switches differently. Perhaps make two different images, a "bighat" and "smallhat," lets say, each with built in positional values. Then put in a condition switch, "body_size == 'big'", "bighat", "body_size != 'big'" "smallhat", or whatever. Then it would call up the hat with the right position relative to the body.

User avatar
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

Re: LiveComposite question

#4 Post by yuren »

xela wrote:Very weird use of a function... You prolly want to use another CS for that.
You're right. Seeing my code on the post made me think that my usage is indeed weird haha.
Onishion wrote:I think the problem is that a lot of bits about LCs are generated once at start-up, and can't be changed after that. Position might be one of those things. I think it's running your function once at start-up and never running it again, although I can't be sure about that. But yeah, like Xela was saying, it might be better to instead use condition switches differently. Perhaps make two different images, a "bighat" and "smallhat," lets say, each with built in positional values. Then put in a condition switch, "body_size == 'big'", "bighat", "body_size != 'big'" "smallhat", or whatever. Then it would call up the hat with the right position relative to the body.

Probably. Using different image might be a good alternative to tackle this, but It's not.. oh well If this is a limitation from the engine then I do have no choice.

I'll see what I can do before creating different images for different position. Thanks a bunch folks!

User avatar
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

Re: LiveComposite question

#5 Post by yuren »

Btw you're right Onishion. These values are computed only once at startup. I got another bug which leads to this again :D

User avatar
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

Re: LiveComposite question

#6 Post by yuren »

Oh dang. How silly of me. I should've just use DynamicDisplayable and this would have been solved long time ago.

Thanks folks for all the effort :)

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: LiveComposite question

#7 Post by Onishion »

Sure, and btw, when I said "make two different images," I didn't mean you had to export two different files, just that you'd have to do something like:

Code: Select all

image bighat:
    "hat.png"
    pos (200, 225)
    
image smallhat:
    "hat.png"
    pos (200, 155)
Or something like that. The position values should work relative to the position of the main image.

User avatar
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

Re: LiveComposite question

#8 Post by yuren »

Onishion wrote:Sure, and btw, when I said "make two different images," I didn't mean you had to export two different files, just that you'd have to do something like:

Code: Select all

image bighat:
    "hat.png"
    pos (200, 225)
    
image smallhat:
    "hat.png"
    pos (200, 155)
Or something like that. The position values should work relative to the position of the main image.
Ah thanks for clarifying. I did not know that the image object also accept position as argument.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: LiveComposite question

#9 Post by Onishion »

Yup, you can do all sorts of fun things inside an image, including adding animations and stuff. And if you reference that image inside an LC, the positions and motions are all relative to where the LC is, so you could like have a moon orbiting a planet, and move the planet around, and the moon will stay in orbit, which is much easier than trying to animate each separately.

User avatar
yuren
Newbie
Posts: 14
Joined: Sat Feb 20, 2016 2:41 am
Projects: chomp2
Github: yosephharyanto
Skype: yosephharyanto
Location: Indonesia
Contact:

Re: LiveComposite question

#10 Post by yuren »

Onishion wrote:Yup, you can do all sorts of fun things inside an image, including adding animations and stuff. And if you reference that image inside an LC, the positions and motions are all relative to where the LC is, so you could like have a moon orbiting a planet, and move the planet around, and the moon will stay in orbit, which is much easier than trying to animate each separately.
:D I see. It's more modular this way. Haha. Good insight!

Post Reply

Who is online

Users browsing this forum: No registered users