|
发表于 2023-6-16 15:46:42
|
显示全部楼层
emmmmm……
楼主已经意识到还有垂直方向平移的需求,所以加了个 direction 参数来控制平移方向。
如果需求斜向平移的话,又怎么处理呢?用if-else语句往往容易陷入这种窘境……
我花了点时间重新写了个组件:
[RenPy] 纯文本查看 复制代码 init python:
from renpy.uguu import GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT, GL_REPEAT
renpy.register_shader("shadertest.texturewarp", variables="""
uniform float u_lod_bias;
uniform sampler2D tex0;
uniform vec2 u_model_size;
uniform vec2 u_warp_speed;
uniform float u_time;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
""",vertex_300="""
v_tex_coord = a_tex_coord + u_time * (u_warp_speed / u_model_size);
""",fragment_300="""
gl_FragColor = texture2D(tex0, v_tex_coord, u_lod_bias);
""")
init python:
class MovingBackground(renpy.Displayable):
def __init__(self, size, image_list, speed_list, **kwargs):
super(MovingBackground, self).__init__(**kwargs)
self.size = size
self.image_list = image_list
self.speed_list = speed_list
def render(self, width, height, st, at):
render = renpy.Render(width, height)
for image, speed in zip(self.image_list, self.speed_list):
t = Transform(image, size=self.size)
child_render = renpy.render(t, width, height, st, at)
child_render.mesh = True
child_render.add_shader('shadertest.texturewarp')
child_render.add_property('gl_texture_wrap', (GL_REPEAT, GL_REPEAT))
child_render.add_uniform('u_model_size', self.size)
child_render.add_uniform('u_warp_speed', speed)
child_render.add_uniform('u_time', st)
render.blit(child_render, (0, 0))
renpy.redraw(self, 0)
return render
没有楼主的寻找图片路径和自定添加路径前缀的部分,可以自行添加,并不冲突。
在脚本中定义图片列表和速度列表,生成一个MovingBackground实例就能像普通image一样使用了:
[RenPy] 纯文本查看 复制代码 define bg_image_list = ['Pixel Art Winter Forest/1.png',
'Pixel Art Winter Forest/2.png',
'Pixel Art Winter Forest/3.png',
'Pixel Art Winter Forest/4.png',
'Pixel Art Winter Forest/5.png',
'Pixel Art Winter Forest/6.png',
'Pixel Art Winter Forest/7.png',
'Pixel Art Winter Forest/8.png',
'Pixel Art Winter Forest/9.png',
'Pixel Art Winter Forest/10.png',
'Pixel Art Winter Forest/11.png',
'Pixel Art Winter Forest/12.png',
'Pixel Art Winter Forest/13.png',
'Pixel Art Winter Forest/14.png',
'Pixel Art Winter Forest/15.png',
'Pixel Art Winter Forest/16.png']
define bg_image_speed_list = [(0, 0),
(10, 0),
(20, 0),
(30, 0),
(40, 0),
(50, 0),
(60, 0),
(70, 0),
(80, 0),
(90, 0),
(100, 0),
(110, 0),
(120, 0),
(130, 0),
(140, 0),
(150, 0)]
image movingbg = MovingBackground((1440, 720), bg_image_list, bg_image_speed_list)
大部分简单的转场应该都可以兼容。
用到的图片作为附件上传了。
|
|