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
Any help would be much appreciated!
The ShowingSwitch code from the wiki looks like this: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.
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),
)
)
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),
)
)
So... does that mean it won't work? I'm totally lost as to what I'm supposed to do to make it workAsceai 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
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 ]
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),
)
)
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
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)
)
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
Users browsing this forum: No registered users