# 初始化
init:
 
    python:
     
        import math
 
        class Shaker(object):
         
            anchors = {
                'top' : 0.0,
                'center' : 0.5,
                'bottom' : 1.0,
                'left' : 0.0,
                'right' : 1.0,
                }
         
            def __init__(self, start, child, dist):
                if start is None:
                    start = child.get_placement()
                #
                self.start = [ self.anchors.get(i, i) for i in start ] # central position
                self.dist = dist   # maximum distance, in pixels, from the starting point
                self.child = child
                 
            def __call__(self, t, sizes):
                # Float to integer... turns floating point numbers to
                # integers.              
                def fti(x, r):
                    if x is None:
                        x = 0
                    if isinstance(x, float):
                        return int(x * r)
                    else:
                        return x
 
                xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]
 
                xpos = xpos - xanchor
                ypos = ypos - yanchor
                 
                nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
                ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
 
                return (int(nx), int(ny), 0, 0)
         
        def _Shake(start, time, child=None, dist=100.0, **properties):
 
            move = Shaker(start, child, dist=dist)
         
            return renpy.display.layout.Motion(move,
                        time,
                        child,
                        add_sizes=True,
                        **properties)
 
        Shake = renpy.curry(_Shake)
    #
 
#

这部分写在label start:前面.

然后就可以在后续演出中使用抖动效果了,例如:

soyo '为什么要演奏春日影!'
with Shake((0, 0, 0, 0), 3.0, dist=30)

0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注