Page 1 of 1
Live Composite and Text
Posted: Fri Feb 12, 2016 1:54 am
by HB38
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:
Can something like this be done?
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 2:15 am
by philat
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.
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 2:46 am
by HB38
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
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 3:59 am
by philat
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?
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 10:07 am
by HB38
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
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 10:54 am
by Kinsman
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
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 4:52 pm
by HB38
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
Re: Live Composite and Text
Posted: Fri Feb 12, 2016 8:55 pm
by philat
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
Re: Live Composite and Text
Posted: Mon Feb 15, 2016 2:59 pm
by HB38
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?
Thanks,
HB38
Re: Live Composite and Text
Posted: Mon Feb 15, 2016 9:15 pm
by neowired
It's probably the text box being too narrow or lacking a defined width?
That would be my guess.
Re: Live Composite and Text
Posted: Mon Feb 15, 2016 9:27 pm
by philat
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.
Re: Live Composite and Text
Posted: Tue Feb 16, 2016 4:51 pm
by HB38
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.
Re: Live Composite and Text
Posted: Fri Jul 05, 2019 3:13 am
by Ishigreensa
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.