TransitionShowingSwitch [SOLVED]

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.
Message
Author
User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

TransitionShowingSwitch [SOLVED]

#1 Post by chocoberrie » Fri Jun 20, 2014 8:08 pm

Hello! :)

I came across a post in the Cookbook forum about using a TransitionShowingSwitch to apply transitions to side images (e.g. one side image fades out and another one fades in).

I'd love to learn how to use this, but being the noob that I am I have no idea where to start with it. Where do I put the code, and how can I define a transition like dissolve?

Any help would be much appreciated! :)
Last edited by chocoberrie on Sun Jun 29, 2014 11:21 pm, edited 1 time in total.

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#2 Post by Asceai » Fri Jun 20, 2014 8:40 pm

You use it where you would use ShowingSwitch. You use it exactly as you would use ShowingSwitch except you supply a transition as the first parameter.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#3 Post by chocoberrie » Fri Jun 20, 2014 9:47 pm

Asceai wrote:You use it where you would use ShowingSwitch. You use it exactly as you would use ShowingSwitch except you supply a transition as the first parameter.
The ShowingSwitch code from the wiki looks like this:

Code: Select all

define e = Character("Eileen",
    show_side_image=ShowingSwitch(
        "eileen happy", Image("eileen_happy_side.png", xalign=1.0, yalign=1.0),
        "eileen vhappy", Image("eileen_vhappy_side.png", xalign=1.0, yalign=1.0),
        None, Image("eileen_happy_default.png", xalign=1.0, yalign=1.0),
        )
    )
Where would I define the transition in this?

Thanks so much for your help!

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#4 Post by Asceai » Fri Jun 20, 2014 9:50 pm

Code: Select all

define e = Character("Eileen",
    show_side_image=TransitionShowingSwitch(Dissolve(0.5, alpha=True),
        "eileen happy", Image("eileen_happy_side.png", xalign=1.0, yalign=1.0),
        "eileen vhappy", Image("eileen_vhappy_side.png", xalign=1.0, yalign=1.0),
        None, Image("eileen_happy_default.png", xalign=1.0, yalign=1.0),
        )
    )

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#5 Post by chocoberrie » Fri Jun 20, 2014 10:08 pm

Unfortunately, I got an error saying that TransitionShowingSwitch wasn't defined. Is there something I'm missing...? :(

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#6 Post by Asceai » Fri Jun 20, 2014 11:36 pm

TransitionShowingSwitch is something I wrote. It's not part of Ren'Py. That's why it's in the cookbook - if it was already in renpy I wouldn't have had to write it =P

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#7 Post by chocoberrie » Fri Jun 20, 2014 11:45 pm

Asceai wrote:TransitionShowingSwitch is something I wrote. It's not part of Ren'Py. That's why it's in the cookbook - if it was already in renpy I wouldn't have had to write it =P
So... does that mean it won't work? I'm totally lost as to what I'm supposed to do to make it work :(

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#8 Post by Asceai » Fri Jun 20, 2014 11:57 pm

I include the code for it right there in the cookbook. Put it in an .rpy file in your project's game directory.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#9 Post by chocoberrie » Sat Jun 21, 2014 1:20 am

I copied and pasted this code into its own .rpy file and I still get the same error.

Here's what I've got:

Code: Select all

init python:
    class TransitionShowingSwitch(renpy.Displayable):
        def __init__(self, transition, *args, **kwargs):
            super(TransitionShowingSwitch, self).__init__(**kwargs)
            self.layer = kwargs.pop('layer', 'master')
            self.transition = transition
            self.d = zip(args[0::2], args[1::2])
            self.time_reset = True
            self.old_d = None
            self.current_d = None
            self.ta = None
        def render(self, width, height, st, at):
            if self.time_reset:
                self.time_reset = False
                self.st = st
                self.at = at
            return renpy.render(self.ta, width, height, st-self.st, at-self.at)
        def per_interact(self):
            change_to = self.current_d #default value
            for name, d in self.d:
                if name is None or renpy.showing(name, layer=self.layer):
                    change_to = d
                    break
            if change_to is not self.current_d:
                self.time_reset = True
                self.old_d = self.current_d
                self.current_d = change_to
                if self.old_d is None:
                    self.old_d = self.current_d
                self.ta = anim.TransitionAnimation(self.old_d, 0.00, self.transition, self.current_d)
                renpy.redraw(self, 0)
        def visit(self):
            return [ self.ta ]

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#10 Post by Asceai » Sat Jun 21, 2014 3:36 am

Show the error you get. You might also want to make the 'init python:' 'init -1 python:' or something to ensure this gets declared before code using it.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#11 Post by chocoberrie » Sat Jun 21, 2014 3:17 pm

Changing "init python" to "init-1 python" did the trick!

Unfortunately, the side images are showing up in the top left corner of the screen. I changed xpos and ypos to 0.0 with no luck. The side images are also not changing. The side image I have for the happy facial expression just stays there, and doesn't fade into any other facial expression.

Here's the ShowingSwitch code I have:

Code: Select all

    $ c = Character("Celeste",
    show_side_image=TransitionShowingSwitch(Dissolve(0.5, alpha=True),
        "celeste happy", Image("Sprites/Girl/Side Images/girl happy_side.png", xalign=0.0, yalign=0.0),
        "celeste curious", Image("Sprites/Girl/Side Images/girl curious_side.png", xalign=0.0, yalign=0.0),
        None, Image("Sprites/Girl/Side Images/girl happy_side.png", xalign=0.0, yalign=0.0),
        )
    )
And here's what I put in the script for dialogue and showing the images:

Code: Select all

label start:
    show celeste happy
    show girl happy at center with moveinleft
    c "Hello!"
    c "My name is Celeste!"
    
    show celeste curious
    c "What's your name?"
    
    return
I thought that just using the show statement would cue the different side images, but it's not working...?

Thanks again for your help! :)

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#12 Post by Asceai » Sun Jun 29, 2014 1:30 am

I'm confused - you're setting xalign and yalign to 0.0 (the top left corner of the screen) and the side image is showing up in the top left corner of the screen... what's the problem, exactly?

EDIT: Well, after working out which xalign and yalign values you want, you also need to give those values to the showingswitch, not the images inside it:

Code: Select all

    $ c = Character("Celeste",
    show_side_image=TransitionShowingSwitch(Dissolve(0.5, alpha=True),
        "celeste happy", Image("Sprites/Girl/Side Images/girl happy_side.png"),
        "celeste curious", Image("Sprites/Girl/Side Images/girl curious_side.png"),
        None, Image("Sprites/Girl/Side Images/girl happy_side.png"),
        xalign=0.0, yalign=0.0)
    )
I'm not sure why the image isn't changing though.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#13 Post by chocoberrie » Sun Jun 29, 2014 12:37 pm

I did what you suggested, but the side image is still at the top left corner of the screen and isn't changing. Am I supposed to use the show statement for the side images just like the full-size sprites, or is that incorrect?

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: TransitionShowingSwitch

#14 Post by Asceai » Sun Jun 29, 2014 9:13 pm

It should just work. Post your updated code.

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: TransitionShowingSwitch

#15 Post by chocoberrie » Sun Jun 29, 2014 9:28 pm

Here's what I've got:

Code: Select all

init:
    image girl happy = "Sprites/Girl/Full-Size/girl_happy.png"
    image girl embarassed = "Sprites/Girl/Full-Size/girl_embarassed.png"
    image girl curious = "Sprites/Girl/Full-Size/girl_curious.png"
    
    image girl happyside = "Sprites/Girl/Side Images/girl happy_side.png"
    image girl embarassedside = "Sprites/Girl/Side Images/girl embarassed_side.png"
    image girl curiousside = "Sprites/Girl/Side Images/girl curious_side.png"
    
    $ c = Character("Celeste",
    show_side_image=TransitionShowingSwitch(Dissolve(0.5, alpha=True),
        "girl happyside", Image("Sprites/Girl/Side Images/girl happy_side.png"),
        "girl curiousside", Image("Sprites/Girl/Side Images/girl curious_side.png"),
        None, Image("Sprites/Girl/Side Images/girl happy_side.png"),
        xalign=0.0, yalign=0.0)
    )
    
init-1 python:
    class TransitionShowingSwitch(renpy.Displayable):
        def __init__(self, transition, *args, **kwargs):
            super(TransitionShowingSwitch, self).__init__(**kwargs)
            self.layer = kwargs.pop('layer', 'master')
            self.transition = transition
            self.d = zip(args[0::2], args[1::2])
            self.time_reset = True
            self.old_d = None
            self.current_d = None
            self.ta = None
        def render(self, width, height, st, at):
            if self.time_reset:
                self.time_reset = False
                self.st = st
                self.at = at
            return renpy.render(self.ta, width, height, st-self.st, at-self.at)
        def per_interact(self):
            for name, d in self.d:
                if name is None or renpy.showing(name, layer=self.layer):
                    change_to = d
                    break
            if change_to is not self.current_d:
                self.time_reset = True
                self.old_d = self.current_d
                self.current_d = change_to
                if self.old_d is None:
                    self.old_d = self.current_d
                self.ta = anim.TransitionAnimation(self.old_d, 0.00, self.transition, self.current_d)
                renpy.redraw(self, 0)
        def visit(self):
            return [ self.ta ]
    
label start:
    show girl happyside
    show girl happy at center with moveinleft
    c "Hello!"
    c "My name is Celeste!"
    
    show girl curiousside
    show girl curious
    c "What's your name?"
    
    return

Post Reply

Who is online

Users browsing this forum: No registered users