本帖最后由 被诅咒的章鱼 于 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指抖动幅度。
以上。
|