找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 17511|回复: 4

[有回复] 请问如何实现窗口抖动效果

[复制链接]
发表于 2020-1-28 02:16:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 任可万岁 于 2020-1-29 01:18 编辑

    在做视觉小说,在一些需要较强视觉冲击力的情景(比如说爆炸,剧烈撞击)下需要用到类似效果。
    自己之前用了闪烁的效果来替代,但是视觉上的冲击感还是感觉不够,请问如何实现,求大佬解答。
发表于 2021-5-7 15:36:08 | 显示全部楼层
本帖最后由 被诅咒的章鱼 于 2021-5-8 08:37 编辑

在LSF翻了半天,最后在官方文档里找到了这个——

有关实现shake的方法:

[RenPy] 纯文本查看 复制代码
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:前面
然后随便定义一个shake、如范例那样——

[RenPy] 纯文本查看 复制代码
init:
    $ sshake = Shake((0, 0, 0, 0), 1.0, dist=15)


前面括号里的四个0是抖动的相对位置,分别指代 向左、向下、向右、向上。

后面1.0指抖动持续时间。

dist指抖动幅度。

以上。

评分

参与人数 1干货 +1 收起 理由
BuErShen + 1 感谢分享!

查看全部评分

回复 支持 1 抱歉 1

使用道具 举报

发表于 2020-2-13 21:48:36 来自手机 | 显示全部楼层
用with vpunch 和with hpunch

评分

参与人数 1干货 +1 收起 理由
BuErShen + 1 感谢解答!

查看全部评分

回复 支持 抱歉

使用道具 举报

发表于 2021-5-7 15:36:51 | 显示全部楼层

评分

参与人数 1干货 +1 收起 理由
BuErShen + 1 感谢分享!

查看全部评分

回复 支持 抱歉

使用道具 举报

发表于 2021-5-12 08:50:43 | 显示全部楼层
有shake函数可以用,不过更建议直接用人物或者画面震动。
回复 支持 抱歉

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-4-24 05:39 , Processed in 0.101480 second(s), 16 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表