File: trans_trans_python.rst

package info (click to toggle)
renpy 8.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 81,768 kB
  • sloc: python: 44,587; ansic: 13,708; javascript: 308; makefile: 41; sh: 13
file content (116 lines) | stat: -rw-r--r-- 3,708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
====================================
Transforms and Transitions in Python
====================================

Python can be used to create new transforms and transitions for use by
Ren'Py scripts.

.. _transforms-python:

Transforms
----------

*Main articles:* :doc:`transforms` *and* :doc:`atl`

A transform is a Python callable that, when called with a displayable,
returns another displayable.

For example::

    init python:

         # This is a transform that uses the right and
         # left transforms.
         def right_or_left(d):
             if switch:
                 return right(d)
             else:
                 return left(d)

The Python equivalent of an ATL transform is a Transform object.

.. class:: Transform(child=None, function=None, **properties)

    A transform applies operations such as cropping, rotation, scaling, and
    alpha-blending to its child. A transform object has fields corresponding
    to the :ref:`transform properties <transform-properties>`, which it applies
    to its child.

    `child`
        The child the transform applies to.

    `function`
        If not none, this is a function that is called when the transform
        is rendered. The function is called with three arguments:

        * The transform object.
        * The shown timebase, in seconds.
        * The animation timebase, in seconds.

        The function should return a delay, in seconds, after which it will
        be called again, or None to be called again at the start of the next
        interaction.

        This function should not have side effects other
        than changing the Transform object in the first argument, and may be
        called at any time with any value to enable prediction.

    Additional keyword arguments are values that transform properties are set
    to. These particular transform properties will be set each time the
    transform is drawn, and so may not be changed after the Transform object
    is created. Fields corresponding to other transform properties, however,
    can be set and changed afterwards, either within the function passed as
    the ``function`` parameter, or immediately before calling the
    :meth:`update` method.

    .. attribute:: hide_request

        This is set to true when the function is called, to indicate that the
        transform is being hidden.

    .. attribute:: hide_response

        If hide request is true, this can be set to false to prevent the
        transform from being hidden.

    .. method:: set_child(child)

        Call this method with a new `child` to change the child of
        this transform.

    .. method:: update()

        This should be called when a transform property field is updated
        outside of the function passed as the `function` argument, to ensure
        that the change takes effect.

.. _transitions-python:

Transitions
-----------

*Main article:* :doc:`transitions`
*See also:* :ref:`atl-transitions`

A transition is a Python callable that, when called with two keyword
arguments, returns a displayable that performs the transition effect.
The two keyword arguments are:

`old_widget`
    A displayable representing the old screen.

`new_widget`
    A displayable representing the new screen.

The returned displayable should have a ``delay`` field, which gives
the number of seconds the transition should run for.

For example::

    init python:

        def dissolve_or_pixellate(old_widget=None, new_widget=None):
            if persistent.want_pixellate:
                return pixellate(old_widget=old_widget, new_widget=new_widget)
            else:
                return dissolve(old_widget=old_widget, new_widget=new_widget)