[SOLVED]Problem with custom portrait code

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
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

[SOLVED]Problem with custom portrait code

#1 Post by mobychan »

Hello everyone ^^

I just realized a problem with my portraits.
I'm using custom code to render the portrait since it consists of multiple possible combinations and I want to have blinking and lip-flapping as well.
It was working before, but now, I believe after I updated to Renpy 6.99.6.739 it broke.

I broke down my code to this:

Code: Select all

init -5 python:
    class Portrait(renpy.Displayable):
        def __init__(self, width=391, height=600, speaker=None, **kwargs):
            try:
                super(Portrait, self).__init__(**kwargs)      
                
                self.width = width
                self.height = height
                self.speaker = speaker
            except Exception as ex:
                renpy.log("Error: Portrait Object for %s couldn't be created.\n%s" % (speaker, ex))
            
        def render(self, width, height, st, at):
            portrait = Image("sylvie_smile.png")
            portrait_render = renpy.render(portrait, self.width, self.height, st, at)

            # Return the render.
            flatten_portrait = renpy.display.render.Render(self.width, self.height)
            flatten_portrait.blit(portrait_render.render_to_texture(True), (0, 0))
            flatten_portrait.depends_on(portrait_render, focus=True)
            return flatten_portrait
And used it in The Question:

Code: Select all

image sylvie portrait = Portrait(width=391, height=600, speaker="Sylvie")
.........................
show sylvie portrait
I have the same effect:
The smaller the window, the smaller and further to the top left is the image(see attached images)


Does anyone have an idea what my problem could be or is it really a problem/change in renpy itself?
Attachments
Bigger window
Bigger window
Small window
Small window
small.PNG (215.18 KiB) Viewed 707 times
Last edited by mobychan on Mon Oct 12, 2015 2:18 am, edited 1 time in total.

OldGoateye
Newbie
Posts: 24
Joined: Fri Oct 09, 2015 4:31 am
Contact:

Re: Problem with custom portrait code

#2 Post by OldGoateye »

Hrmn, I'd try using the nightly build and see if that solves your problem; if so, it's just something to be ironed out, and if not you can roll back, possibly to a version that worked?
Nothing in that formula seems like it should cause such strange alignment and resizing issues.
I really wish I could give more detailed help, since you helped me... :(
But it seems like portraits should be displaying correctly.

I'll have to sleep on it, but I'm assuming it worked both windowed (various sizes) and full-screen before?

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Problem with custom portrait code

#3 Post by mobychan »

I'll try the nightly build at home, thanks for the suggestion^^

I'd really like to stick to the newest version, since our game is not that far implemented yet apart from code parts like these which I'd really like to reuse in future games

Yes, it worked in various sizes and full-screen before

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Problem with custom portrait code

#4 Post by PyTom »

render_to_texture is not a public API, and it changed recently. It now does things at drawable resolution, which may be weird. Why are you doing it here anyway?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Problem with custom portrait code

#5 Post by mobychan »

I found it in a tutorial a few month ago for doing lip flapping and stuff, but if it changed I'll have to see what else to use^^

Do you know an alternative right away?
if not I'll have to poke around a bit ^^

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Problem with custom portrait code

#6 Post by PyTom »

Code: Select all

        def render(self, width, height, st, at):
            portrait = Image("sylvie_smile.png")
            portrait_render = renpy.render(portrait, self.width, self.height, st, at)

            # Return the render.
            flatten_portrait = renpy.display.render.Render(self.width, self.height)
            flatten_portrait.blit(portrait_render, (0, 0))
            return flatten_portrait
This is the code without RTT - which should work, and be faster.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Problem with custom portrait code

#7 Post by mobychan »

Thanks, I'll test it tomorrow^^

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Problem with custom portrait code

#8 Post by mobychan »

I just tested the code and it's working perfectly, thank you very much^^

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Sugar_and_rice