Reference Manual: (offline | online) Quickstart: (offline | online)

Transitions

By default, Ren'Py displays each scene by replacing the old scene with a new one. This is appropriate in general (such as for emotion changes), but it may be boring for large changes, such as a change in location or a character entering or leaving the scene. Ren'Py supports transitions that control how changes to the scene lists are exposed to the user.

Transitions occur between the last scene that was shown to the user, and the current scene that has been updated using the scene, show, or hide statements. A transition runs for a given amount of time, but may be dismissed early by the user. Once a transition is shown, the scene is considered shown for the purposes of future transitions.

Transitions are introduced with the with statement. The with statement takes an expression that is suitable for use with the with statement (that is, a callable that takes as input two scene lists), and runs that transition. Alternatively, if the expression is None, then the with statement has the effect of showing the scene to the user, and returning instantly. This is useful in conjunction with a future with statement, so that only some changes to the scene list will be transitioned in.

An example is in order. First, let us define a few objects that can be passed in as the argument to a with statement:

init:
    # Fades to black, then to the new scene.
    fade = Fade(0.5, 0, 0.5)

    # Dissolves between old and new scenes.
    dissolve = Dissolve(0.5)

A simple use of with would be to place it after a series of show and hide statements of the program. As an example:

scene bg whitehouse
show eileen happy
with fade

This series of statements will cause the old scene (displayed before these statements started) to fade to black, and be replaced with the new scene all at once. This is a useful behavior, for example, when we are replacing a scene with a new one, such as when the story changes locations.

scene bg whitehouse
with None
show eileen happy
with dissolve

The with None statement is useful to break changes to the scene list into parts, as in the example above. When run, the background will be instantly shown, and then the character image will be dissolved in over the background.

Another use of the with None statement is to remove transient elements before a transition begins. By default, the scene list includes transient elements like dialogue, thoughts, and menus. with None always executes without these elements, and so gets rid of them.

The show, hide, and scene statements all take a with clause. One of these statement with a with clause associated with it is actually converted into three statements: A with None statement, the original statement sans the with clause, and the with clause as a with statement. For example:

scene bg whitehouse with fade
show eileen happy at left with dissolve
show lucy happy at right with dissolve

becomes

with None
scene bg whitehouse
with fade
with None
show eileen happy at left
with dissolve
with None
show lucy happy at right
with dissolve

This has the effect of fading out the old scene and fading in the new background, then dissolving in the characters one after the other.

We also allow with clauses to be supplied for say and menu statements. When a with clause is supplied on one of these statements, the transition is used to introduce the say or menu element. For example,

e "How are you doing?" with dissolve

Will dissolve in a line of dialogue. The line of dialogue will be dismissed immediately, unless it is followed by a with statement or clause that causes it to transition to something else.

There are two variables that control transitions:

Pre-Defined Transitions

Definition: fade

An instance of the Fade transition that takes 0.5 seconds to fade to black, and then 0.5 seconds to fade to the new screen.

Definition: dissolve

An instance of the Dissolve transition that takes 0.5 seconds to complete.

Definition: pixellate

An instance of the Pixellate transition, which takes 1 second to complete, and creates pixels as big as 32x32 over the course of 5 steps in either direction.

Definition: move

An instance of the MoveTransition transition, this takes 0.5 seconds to move images that changed position to their new locations.

Definition: wiperight

An instance of CropMove that takes 1 second to wipe the screen right.

Definition: wipeleft

An instance of CropMove that takes 1 second to wipe the screen left.

Definition: wipeup

An instance of CropMove that takes 1 second to wipe the screen up.

Definition: wipedown

An instance of CropMove that takes 1 second to wipe the screen down.

Definition: slideright

An instance of CropMove that takes 1 second to slide the screen right.

Definition: slideleft

An instance of CropMove that takes 1 second to slide the screen left.

Definition: slideup

An instance of CropMove that takes 1 second to slide the screen up.

Definition: slidedown

An instance of CropMove that takes 1 second to slide the screen down.

Definition: slideawayright

An instance of CropMove that takes 1 second to slide the screen away and to the right.

Definition: slideawayleft

An instance of CropMove that takes 1 second to slide the screen away and to the left.

Definition: slideawayup

An instance of CropMove that takes 1 second to slide the screen away and to the up.

Definition: slideawaydown

An instance of CropMove that takes 1 second to slide the screen away and to the down.

Definition: irisout

An instance of CropMove that irises the screen out for 1 second.

Definition: irisin

An instance of CropMove that irises the screen in for 1 second.

Transition Constructors

The following are functions that return things useful as transitions. The user should not supply the new_widget or old_widget parameters, as these are supplied by Ren'Py when a transition begins.

Function: CropMove( time, mode='fromleft', startcrop=(0.0, 0.0, 0.0, 1.0), startpos=(0.0, 0.0), endcrop=(0.0, 0.0, 1.0, 1.0), endpos=(0.0, 0.0), topnew=True, old_widget=None, new_widget=None)

The CropMove transition works by placing the old and the new image on two layers, called the top and the bottom. (Normally the new image is on the top, but that can be changed in some modes.) The bottom layer is always drawn in full. The top image is first cropped to a rectangle, and then that rectangle drawn onto the screen at a specified position. Start and end crop rectangles and positions can be selected by the supplied mode, or specified manually. The result is a surprisingly flexible transition.

This transition has many modes, simplifying its use. We can group these modes into three groups: wipes, slides, and other.

In a wipe, the image stays fixed, and more of it is revealed as the transition progresses. For example, in "wiperight", a wipe from left to right, first the left edge of the image is revealed at the left edge of the screen, then the center of the image, and finally the right side of the image at the right of the screen. Other supported wipes are "wipeleft", "wipedown", and "wipeup".

In a slide, the image moves. So in a "slideright", the right edge of the image starts at the left edge of the screen, and moves to the right as the transition progresses. Other slides are "slideleft", "slidedown", and "slideup".

There are also slideaways, in which the old image moves on top of the new image. Slideaways include "slideawayright", "slideawayleft", "slideawayup", and "slideawaydown".

We also support a rectangular iris in with "irisin" and a rectangular iris out with "irisout". Finally, "custom" lets the user define new transitions, if these ones are not enough.

time - The time that this transition will last for, in seconds.

mode - One of the modes given above.

The following parameters are only respected if the mode is "custom".

startcrop - The starting rectangle that is cropped out of the top image. A 4-element tuple containing x, y, width, and height.

startpos - The starting place that the top image is drawn to the screen at, a 2-element tuple containing x and y.

startcrop - The starting rectangle that is cropped out of the top image. A 4-element tuple containing x, y, width, and height.

startpos - The starting place that the top image is drawn to the screen at, a 2-element tuple containing x and y.

topnew - If True, the top layer contains the new image. Otherwise, the top layer contains the old image.

Function: ImageDissolve( image, time, ramplen=8, ramptype='linear', ramp=None, reverse=False, old_widget=None, new_widget=None)

This dissolves the old scene into the new scene, using an image to control the dissolve process.

A list of values is used to control this mapping. This list of values consists 256 fully transparent values, a ramp (of a specified number of steps) from full transparency to full opacity, and 256 fully opaque values. A 256 entry window is slid over this list, and the values found within are used to map the red channel of the image onto the opacity of the new scene.

Basically, this means that white pixels come in first, black last, and the ramp controls the sharpness of the transition.

image - The image that will be used to control this transition. The image should be the same size as the scene being dissolved.

time - The amount of time the dissolve will take.

ramplen - The number of pixels of ramp to use. This defaults to 8.

ramptype - Type of alpha ramp. Possible types are: linear, cube, dcube, mcube. Default is linear. Non-linear types must have ramplen >= 8. "cube": Ease in, sharp out. "dcube": Sharp in, sharp out. "mcube": Ease in, ease out.

ramp - If given, this is expected to be a sequence of integers in the range 0 to 255. This sequence explicitly gives the ramp to be used. If given, this overrides ramplen and ramptype.

reverse - This reverses the ramp and the direction of the window slide. When True, black pixels dissolve in first, and white pixels come in last.

Function: MoveTransition( delay, factory=None, enter_factory=None, leave_factory=None)

This transition attempts to find images that have changed position, and moves them from the old position to the new transition, taking delay seconds to complete the move.

If factory is given, it is expected to be a function that takes as arguments: an old position, a new position, the delay, and a displayable, and to return a displayable as an argument. If not given, the default behavior is to move the displayable from the starting to the ending positions.

If enter_factory or leave_factory are given, they are expected to be functions that take as arguments a position, a delay, and a displayable, and return a displayable. They are applied to displayables that are entering or leaving the scene, respectively. The default is to show in place displayables that are entering, and not to show those that are leaving.

Images are considered to be the same if they have the same tag, in the same way that the tag is used to determine which image to replace or to hide. They are also considered to be the same if they are the same displayable.

If you use this transition to slide an image off the side of the screen, remember to hide it when you are done. (Or just use it with a leave_factory.)

There are several constructors that create functions for use with enter_factory and leave_factory:

Some transitions can also be applied to specific layers, using the renpy.transition function. Only transitions that are not completely opaque can be used in this way.

Reference Manual: (offline | online) Quickstart: (offline | online)