Live Composite and Text

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
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Live Composite and Text

#1 Post by HB38 » Fri Feb 12, 2016 1:54 am

I'm wondering if there is some way I can integrate text into a live composite - I have the following code that I'm using to build a sort of 'map marker' for each character in the game:

Code: Select all

image character_0_doll_map_info = LiveComposite(
    
    (0,0),
    
    (0,0), "images/map/map_info_hover.png",
    
    (40,70), "character_0_doll_chibi",
    
    (0,0), "images/map/map_info_normal.png",

    )

This is great, but I was hoping to stick the characters name dynamically in this as well. I suppose I could just have the image displayed at XX location and then stick the text over that in a vbox… but a cleaner integration here in the LiveComposite would mean that I didn't have to add this on every map screen in the game.

Looking to basically add something like this (that works, obviously) at the tail end of the above code:

Code: Select all

    (0,0), text "char_list[0].full"
Can something like this be done?

philat
Eileen-Class Veteran
Posts: 1742
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Live Composite and Text

#2 Post by philat » Fri Feb 12, 2016 2:15 am

Yes, but the order of definitions is going to be tricky.

You can use Text(variable_name) to show a string variable as a displayable. http://www.renpy.org/doc/html/text.html ... splayables

However, images must be defined in init (prior to the game starts), whereas your characters will be randomly generated after the game starts (unless something has changed since you last came around ;) ). Same problem for images -- it's going to be difficult to randomly generate LiveComposites with images, although not impossible. It's hard to say without knowing more.

User avatar
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Live Composite and Text

#3 Post by HB38 » Fri Feb 12, 2016 2:46 am

philat wrote:Yes, but the order of definitions is going to be tricky.

You can use Text(variable_name) to show a string variable as a displayable. http://www.renpy.org/doc/html/text.html ... splayables

However, images must be defined in init (prior to the game starts), whereas your characters will be randomly generated after the game starts (unless something has changed since you last came around ;) ). Same problem for images -- it's going to be difficult to randomly generate LiveComposites with images, although not impossible. It's hard to say without knowing more.
Well, I got it to display dummy text but you're right - it blows up because those variables are set at game start and not from like int -2 (or whatever)…

What other info would be you need to be able to assist? :)

(Thanks again Philat)

- HB38

philat
Eileen-Class Veteran
Posts: 1742
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Live Composite and Text

#4 Post by philat » Fri Feb 12, 2016 3:59 am

Well, for instance, ARE you going to try to randomize the images? I assumed that you might want to, but you're referencing what seems to be a static image name in the LiveComposite, so I wasn't sure. Also, how are you adding this LiveComposite to a screen, and in what capacity?

User avatar
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Live Composite and Text

#5 Post by HB38 » Fri Feb 12, 2016 10:07 am

philat wrote:Well, for instance, ARE you going to try to randomize the images? I assumed that you might want to, but you're referencing what seems to be a static image name in the LiveComposite, so I wasn't sure. Also, how are you adding this LiveComposite to a screen, and in what capacity?
The names are randomized at the start, but the info/image is static - character_0_doll_map_info will always have the same name, once it's assigned. Because these show up on the main map it doesn't have anything to do with the 'current character' stuff I was doing previously (since up to three of these will show up at once).

And yes, I'm showing them on a screen - I actually have found you can add LiveComposites as image buttons, but they don't actually function (bug?) so I've also added a shadow under them that functions as the image button itself. Basically you click on a location, you "go there" and you see three characters… at which point you click on the button I've created (character_0_doll_map_info/it's shadow) and then go the the label where you talk to them.

I could totally add the names on this scene, but it's going to require a bunch more work than I had hoped for down the road so I'd rather integrate it into the Composite if possible.

I was thinking if I defined every name in the game as an image (all 30 first and last names), I could probably then call them dynamically in the composite?

- HB38

Kinsman
Regular
Posts: 130
Joined: Sun Jul 26, 2009 7:07 pm
Location: Fredericton, NB, Canada
Contact:

Re: Live Composite and Text

#6 Post by Kinsman » Fri Feb 12, 2016 10:54 am

While images are defined before the game starts, you can create displayables at any time.

Code: Select all

python:
    def create_marker(chibi,name):
        lc = LiveComposite(
        (0,0),
        (0,0), "images/map/map_info_hover.png",
        (40,70), chibi,
        (0,0), "images/map/map_info_normal.png",
        (0,0), Text(name)
        )
        return lc
You can also insert python code into screen code, and do something like this:

Code: Select all


$characterlist = [ ["character_0_doll_map_info","Alice"] , ["character_1_doll_map_info","Bob"] ]

screen map:
    for character in characterlist:
        $marker = create_marker(character[0], character[1])
        add marker
        # etc etc
Flash To Ren'Py Exporter
See the Cookbook thread

User avatar
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Live Composite and Text

#7 Post by HB38 » Fri Feb 12, 2016 4:52 pm

HB38 wrote:I was thinking if I defined every name in the game as an image (all 30 first and last names), I could probably then call them dynamically in the composite?
This mostly worked - I defined every name I had (first and last):

Code: Select all

image Adam = Text("Adam")
image Alicia = Text("Alicia")
image Allison = Text("Allison")
image Anna = Text("Anna")
image Brian = Text("Brian")
…
And then added this to the marker:

Code: Select all

image character_0_doll_map_info = LiveComposite(
    
    (0,0),
    
    (0,0), "images/map/map_info_hover.png",
    
    (40,70), "character_0_doll_chibi",
    
    (0,0), "images/map/map_info_normal.png",
    
    (52,45), "[char_list[0].first]",
    
    (155,45), "[char_list[0].last]",
    
    )
However… because the first names are of differing length I either get an ugly gap between the names or they over run each other. There's no way to set one image (text) flush to the right of another?



Kinsman,

I did see your code and I tried playing around with it but I think it may cause further issues in this case due to nested variables. If I can find an easy solution to the above, I may revisit your solution.

Thanks for your input,
HB38

philat
Eileen-Class Veteran
Posts: 1742
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Live Composite and Text

#8 Post by philat » Fri Feb 12, 2016 8:55 pm

HB38 wrote: However… because the first names are of differing length I either get an ugly gap between the names or they over run each other. There's no way to set one image (text) flush to the right of another?
No. LiveComposite positions things in a fixed place -- the pixels you give it.

DynamicDisplayable may work here, but we're quickly reaching territory where I'm not entirely sure how you want the game to function so it's difficult to offer optimal advice. Like, thanks for the explanation above, but I'm still not sure how you want the characters to behave, what the screen is for, how you're choosing three out of X available characters, etc.

Code: Select all

image character_0_doll_map_info = LiveComposite(
    
    (0,0),
    
    (0,0), "images/map/map_info_hover.png",
    
    (40,70), "character_0_doll_chibi",
    
    (0,0), "images/map/map_info_normal.png",
    
    (52,45), DynamicDisplayable(ddname, char=0) # this line replaces your first and last names
   
    )

init python:
    def ddname(st, at, char):
        try:
            return Text(char_list[char].full), None
        except:
            return Null(), None

    class CharInfo():
        def __init__(self, full):
            self.full = full

User avatar
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Live Composite and Text

#9 Post by HB38 » Mon Feb 15, 2016 2:59 pm

philat wrote:
HB38 wrote: However… because the first names are of differing length I either get an ugly gap between the names or they over run each other. There's no way to set one image (text) flush to the right of another?
No. LiveComposite positions things in a fixed place -- the pixels you give it.

DynamicDisplayable may work here, but we're quickly reaching territory where I'm not entirely sure how you want the game to function so it's difficult to offer optimal advice. Like, thanks for the explanation above, but I'm still not sure how you want the characters to behave, what the screen is for, how you're choosing three out of X available characters, etc.

Code: Select all

image character_0_doll_map_info = LiveComposite(
    
    (0,0),
    
    (0,0), "images/map/map_info_hover.png",
    
    (40,70), "character_0_doll_chibi",
    
    (0,0), "images/map/map_info_normal.png",
    
    (52,45), DynamicDisplayable(ddname, char=0) # this line replaces your first and last names
   
    )

init python:
    def ddname(st, at, char):
        try:
            return Text(char_list[char].full), None
        except:
            return Null(), None

    class CharInfo():
        def __init__(self, full):
            self.full = full
This almost worked perfectly -- however, it keeps throwing the first name on one line, and the last name on a second line. I do have this in the code from earlier when it comes to the character info:

Code: Select all

            self.first = first
            self.last = last
            self.full = first + " " + last
I tried changing the displayable to first and last, but it also displayed that as two lines. This works fine in other places in game so I'm not sure why the displayable is showing it as multiple lines?
Screen Shot 2016-02-15 at 1.57.54 PM.png
Thanks,
HB38

neowired
Regular
Posts: 199
Joined: Mon Dec 01, 2008 2:33 pm
Contact:

Re: Live Composite and Text

#10 Post by neowired » Mon Feb 15, 2016 9:15 pm

It's probably the text box being too narrow or lacking a defined width?
That would be my guess.

philat
Eileen-Class Veteran
Posts: 1742
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Live Composite and Text

#11 Post by philat » Mon Feb 15, 2016 9:27 pm

Yes, it's a width problem. The only time I can reproduce what you're saying is happening is if the width of the LiveComposite itself is too small.

User avatar
HB38
Regular
Posts: 53
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Live Composite and Text

#12 Post by HB38 » Tue Feb 16, 2016 4:51 pm

philat wrote:Yes, it's a width problem. The only time I can reproduce what you're saying is happening is if the width of the LiveComposite itself is too small.
This is going to sound like a dumb question… where does one set the width? As far as I knew for a LC you placed things in it given a specific set of X,Y cords and there were no boundaries? I'm surprised it's even an issue since the entire orange background is part of the composite as well.

Ishigreensa
Newbie
Posts: 17
Joined: Sun Jul 06, 2014 8:11 am
Contact:

Re: Live Composite and Text

#13 Post by Ishigreensa » Fri Jul 05, 2019 3:13 am

You can fix it if you put the first name as one image and the last name as a second image.
then in the (0,0) x and y declaration just before the names, have it show the names like this....
(15,20),("%s"%first_name),
(50,20),("%s"%last_name)
),.1

Just make sure you have the second name's x far enough over for longer first names....
and that your window is wide enough to display both names where the last name starts at the place you marked it at (50) pixels + characters long.

It won't be flush with each other, but it will be side by side in the top of the image like you wanted.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Shocking Alberto