LiveComposite() centering and passing a list to HBox()

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
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

LiveComposite() centering and passing a list to HBox()

#1 Post by kitsalai » Sun Jun 14, 2015 2:27 am

I have 2 questions. They're somewhat unrelated but they're both short so I decided to put them into one post.

1. I'm using LiveComposite to merge some text with an image. I want to center the text (I will have many words, each with different lengths) but LiveComposite only takes x and y coordinates. Is it possible for LiveComposite to take an xcenter or xalign property?

Code: Select all

image word = LiveComposite(
    (100, 30),
    (0, 0), "background.png",
    (0.5, 0.5), Text("word"))
2. I have multiple images, which will be defined in a list, and I want to pass them into HBox() to merge them all together. However, Renpy interprets the list as one image rather than multiple images. Writing it out separately obviously works but that won't work if my images vary.

Code: Select all

init python:
    renpy.image('cat', 'cat.png')
    renpy.image('dog', 'dog.png')

    # this does work
    renpy.image('two_words', HBox('cat', 'dog'))

    # this does not work (compile error)
    word_list = ['cat', 'dog']
    renpy.image('two_words', HBox(word_list))
Thank you in advanced for your time.

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

Re: LiveComposite() centering and passing a list to HBox()

#2 Post by xela » Sun Jun 14, 2015 4:14 am

1) Try Fixed and Transforms or is there a reason you need this to be LC?

2) Try using ImageReference and maybe unpack the values (I don't remember if you need to provide HBox with a list or unpacked args for children).
Like what we're doing? Support us at:
Image

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#3 Post by orz » Sun Jun 14, 2015 12:09 pm

I have multiple images, which will be defined in a list, and I want to pass them into HBox() to merge them all together.
I'm guessing that you mean to just have a variable length list of images that you want added to an hbox.

Why not iterate over the list in whatever screen you're using?

Code: Select all

init python:
    renpy.image('cat', 'logo.png')
    renpy.image('dog', 'logo.png')
    word_list = ["cat", "dog"]

label start:
    call screen test()
    return

screen test:
    fixed:
        hbox:
            for val in word_list:
                add val

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#4 Post by kitsalai » Mon Jun 15, 2015 12:57 am

@xela: My apologizes for not being clear. The main reason why I'm using LiveComposite is so that I can apply animations on the merged image. For example, a linear movement on the "word" image.

I tried using Fixed and what's strange is that it doesn't work on the Text object, only the image. Either way, using Fixed overrides any ATL statements so it isn't too useful in this scenario.

@orz: Yes, my lists and images all have variable length which makes thing fun. Furthermore, I'm not using screens because I want to use ATL statements on the "two_words" image. From my knowledge, I don't think there's a way to create rotational/linear motions with frames. Is that correct?



Last bit. I'm improving on some old code I wrote and combining images into one image would be the easiest to do what I want. Technically I could rewrite the code to animate each image separately, but it'll take a ton of time especially when I'll have to calculate each of their positions so everything is centered and side by side with the right spaces.

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

Re: LiveComposite() centering and passing a list to HBox()

#5 Post by xela » Mon Jun 15, 2015 1:52 am

Maybe you're just using it incorrectly? Fixed given xysize=() positional argument, containing At() displayable which would provide the ATL instructions should work with any displayable, Text or imagelike. At least it did for me in the past.

I haven't used LC for a while and I've never tried to use it in a way that you do, it seems redundant or at least I cannot see any advantage in it. You can apply ATL instructions to Fixed, just like you could to LC.
Like what we're doing? Support us at:
Image

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

Re: LiveComposite() centering and passing a list to HBox()

#6 Post by Onishion » Mon Jun 15, 2015 5:18 am

I know in the past I wasn't able to get any sort of positional commands to do anything to an item inside an LC, that is, if I set an LC layer to be (0.5,0.5), then nothing I did to try and move that layer around using Transforms would actually cause it to move. Using the "contains" command allowed me to make a similar structure to LC, but would allow outside transformations to be applied.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#7 Post by nyaatrap » Mon Jun 15, 2015 11:27 am

Code: Select all

LiveComposite((x,y), (Ax,Ay),DisplayableA,(Bx,By),DisplayableB)

Code: Select all

Fixed(At(DisplayableA, Position(pos=(Ax,Ay))), At(DisplayableB, Position(pos=(Bx,By))), xysize=(x,y))
They would work same - even there can be unnoticeable performance difference. But Fixed allows to use Transform instead of Position (It looks changed behavior in 6.99. https://github.com/renpy/renpy/commit/c ... 5f9f814d0c)
To unpack a list, Hbox(*[Image("a.png"), Image("b.png")]) should work. I'm using Fixed(*list_of_displayables, fit_first=True).

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#8 Post by kitsalai » Mon Jun 15, 2015 7:03 pm

To unpack a list, Hbox(*[Image("a.png"), Image("b.png")]) should work. I'm using Fixed(*list_of_displayables, fit_first=True).
Works brilliantly. Did not realize that adding a star unpacks a list.



On the problem with centering with LC, here's some sample code I wrote up for testing your suggestions with comments:

Code: Select all

init python:
    renpy.image("word", LiveComposite((100, 30), \
        (0, 0), "background.png",
        (0.5, 0), Text("word")))

label start:
    show word:
        align (0.0, 0.5)
        linear 1.0 xalign 1.0
    "..."
LiveComposite: Animation works, text not aligned (xpos is defined as 100*0.5 which is neat though)

Code: Select all

init python:
    renpy.image("word", Fixed( \
        At("background.png", Position(xysize=(100, 30), pos=(0, 0))), \
        At(Text("word"), Position(xysize=(100, 30), xalign=0.5)))
...
Fixed: Animation doesn't work, because Position overrides the ATL statement. I tried other variations like using xcenter but no dice.

Code: Select all

init:
    image word:
        contains:
            "background.png"
        contains:
            Text("word")
            xalign 0.5
...
contains: Same problem with no animation. Transform is dominant over the ATL.



I took a look at PyTom's commit but frankly it doesn't look like it changes much other than how the image is displayed... Well my programming skills are horrible so I never bothered looking into the source code.

I think one workaround may be to declare the text image, grab its width, and then calculate the xpos to align the text from there. I'm uncertain how to get the image width though, but when I find time I'll try to work on this if there's no other solutions.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#9 Post by trooper6 » Mon Jun 15, 2015 8:32 pm

nyaatrap wrote: To unpack a list, Hbox(*[Image("a.png"), Image("b.png")]) should work. I'm using Fixed(*list_of_displayables, fit_first=True).
I'd never heard of an asterisk unpacking a list...that is very exciting. In trying to get it to work...I ran into a few troubles.
How would you translate this screen using a for loop, into a screen using an asterisk to unpack the list?

Code: Select all

screen contacts_screen():
    frame:
        has vbox
        text "Contacts:"
        for item in contact_list:
            text ("[item]")
Oh...or even...how would you use the asterisk in this situation?

Code: Select all

default master_list = ["John", "Jane", "Gertrude"]
label start:
    python:
        for item in master_list:
            narrator("The word is [item]")
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#10 Post by nyaatrap » Mon Jun 15, 2015 9:47 pm

kitsalai wrote:Fixed: Animation doesn't work, because Position overrides the ATL statement. I tried other variations like using xcenter but no dice.
Position is a deprecated function for it's used as At clauses. To work with ATL, Transform should be used.
trooper6 wrote: How would you translate this screen using a for loop, into a screen using an asterisk to unpack the list?

Code: Select all

screen contacts_screen():
    frame:
        has vbox
        text "Contacts:"
        for item in contact_list:
            text ("[item]")
Oh...or even...how would you use the asterisk in this situation?

Code: Select all

default master_list = ["John", "Jane", "Gertrude"]
label start:
    python:
        for item in master_list:
            narrator("The word is [item]")
I don't think unpack is useful here (text "{}{}{}".format(*list) is possible though). text "".join(list) or just using for loop normally would be better.

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#11 Post by kitsalai » Tue Jun 16, 2015 3:04 am

trooper6 wrote:How would you translate this screen using a for loop, into a screen using an asterisk to unpack the list?
Somewhat off topic but when I was reading about it, the asterisk is for unpacking lists through functions in python and two asterisks for dictionaries. If you couldn't already, maybe you could use it in the parameters in a screen or label? Otherwise, I don't think the asterisk would be useful for renpy coding. Anyway, nyaatrap's method of using the join function is the standard way to display lists.
nyaatrap wrote:Position is a deprecated function for it's used as At clauses. To work with ATL, Transform should be used.
I'm a bit confused as to what you're trying to say. I understand Position and At don't work together from what I've tested, but from your previous post it looks like in version 6.99 (which I'm using) the use of Transform was removed and replaced with Position. Does that mean Fixed is out of the question for what I'm trying to do right now?
Last edited by kitsalai on Tue Jun 16, 2015 7:21 pm, edited 1 time in total.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#12 Post by nyaatrap » Tue Jun 16, 2015 11:45 am

Forget about Position(). This function should be only used internally or as a transition. I just wanted to tell that LiveComposite is limited in Position, but Fixed should have more flexibility.
Fixed should work with ATL and Transform(). I don't know why it doesn't work. I guess transform properties are conflicted somewhere, or image size is not properly evaluated. When you use Fixed, you have to explicitly give the size of Fixed to work with other transform properties.

In an alternative way, You can try http://www.renpy.org/doc/html/displayin ... age_bounds

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: LiveComposite() centering and passing a list to HBox()

#13 Post by kitsalai » Fri Jun 19, 2015 1:03 am

Tested Fixed a little more with Transform() and explicitly stating size=(100, 30) doesn't change anything.

I looked into get_image_bounds, but unfortunately it doesn't work and returns None. I realized it's because I'm working within the init block and get_image_bounds only returns the image properties once the image is shown on a layer.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]