找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1860|回复: 1

[经验] 屏幕震动 + 立绘震动的自用代码

[复制链接]
发表于 2022-7-4 16:44:08 | 显示全部楼层 |阅读模式

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

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

×
【屏幕震动】和【立绘左右震动】
屏幕震动在wiki里找的,立绘移动是我写的,具体表现为角色立绘快速左右来回移动,类似于“躲避”动作
移动就是一种动画,可以参考代码
萌新第一次发帖子,求轻拍。。。


【屏幕震动】
出处
https://www.renpy.org/wiki/renpy/doc/cookbook/Shake_effect

###
#放在script文件最前面, 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)
        #
    #Shake(x-position, y-position, xanchor, yanchor.)


#使用范例(震动3.0秒 距离30):
c “这里屏幕会震动。”
with Shake((0, 0, 0, 0), 3.0, dist=30)



【立绘左右震动】
    show [角色立绘名字]:
        # 最初出现在x坐标中央,y坐标最下方
         xalign 0.5 yalign 0.0

         #花0.15秒 向右侧移动到x坐标0.75
         linear 0.15 xalign 0.75

         # 花0.25秒 向左侧移动到x坐标0.3
         linear 0.25 xalign 0.3

         # 花0.14秒 向右侧移动到x坐标0.75
         linear 0.15 xalign 0.75

         # 花0.25秒 向左侧移动到x坐标0.3
         linear 0.25 xalign 0.3

         # 花0.14秒  回到原点(横坐标中央)
         linear 0.14 xalign 0.5

#可以自己改成别的动画
发表于 2022-7-5 02:10:57 | 显示全部楼层
放一个我用官方教程做出的效果:
回复 支持 抱歉

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 10:48 , Processed in 0.114141 second(s), 12 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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