|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Ren'Py引擎从入门到放弃(支线3)——简单粒子效果
https://www.renpy.cn/forum.php?mod=viewthread&tid=296
(出处: RenPy中文空间)
原帖是这个. 但是年代有些久远, 并不能拿来直接用. 研究了一下, 现在的代码可以直接拿来用了.
比较重要的更新点有三个.
1. 在screen 里面使用, 而不是在label里面使用.
2. 遍历字典的方式改为for d in list(self.shown.keys()): 也就是先把字典所有的key值保存为一个list然后再遍历, 不然在遍历的过程中改变字典的大小会报错.
3. render.blit(d.render(width, height, st, at),(self.around[0] + d.radius * math.cos(d.angle), d.around[1] + d.radius * math.sin(d.angle))), 原本是读取(d.xpos, d.ypos), 也就是直接读取粒子的pos, 但是因为用的是around, 所以好像读取不到, 就暴力算了.
[RenPy] 纯文本查看 复制代码
transform particle(d, delay = 0.0, angle = 0, radius=200, keep_time= 1.0, current_around = (config.screen_width/2,config.screen_height/2), init_zoom = 1.0, target_zoom = 1.0):
# 这个效果是, 射出去泡泡, 泡泡会变大, 并且逐渐的渐隐.
d
alpha 1.0
subpixel True
around current_around
radius 0
angle angle
zoom init_zoom
alpha 1.0
linear keep_time radius radius zoom target_zoom alpha 0.0
init python:
class BubbleShoot(renpy.Displayable):
def __init__(self, displayable, interval = (0.02,0.04), keep_time=(0.15,0.3), around=(config.screen_width/2, config.screen_height/2),angle=(0,360),radius=(50,75),particles=None, zoom_init_range=(1.0,1.5), zoom_end_range=(1.5,2.5),**kwargs):
super(BubbleShoot, self).__init__(**kwargs)
self.d = [renpy.easy.displayable(d) for d in displayable] if isinstance(displayable, (set, list, tuple)) else [renpy.easy.displayable(displayable)]
self.interval = interval
self.keep_time = keep_time
self.around = around
self.angle = angle
self.radius = radius
self.particles = particles
self.zoom_init_range = zoom_init_range
self.zoom_end_range = zoom_end_range
self.next = 0
self.particle = 0
self.shown = {}
def render(self, width, height, st, at):
rp = store.renpy
render = rp.Render(width, height)
if not (self.particles and self.particle >= self.particles) and self.next <= st:
keep_time = rp.random.uniform(self.keep_time[0], self.keep_time[1])
angle = rp.random.randrange(self.angle[0], self.angle[1])
radius = rp.random.randrange(self.radius[0], self.radius[1])
zoom_init = rp.random.uniform(self.zoom_init_range[0], self.zoom_init_range[1])
zoom_end = rp.random.uniform(self.zoom_end_range[0], self.zoom_end_range[1])
self.shown[st + keep_time] = particle(rp.random.choice(self.d), st, angle, radius, keep_time, self.around, zoom_init,zoom_end)
self.next = st + rp.random.uniform(self.interval[0], self.interval[1])
if self.particles:
self.particle = self.particle + 1
for d in list(self.shown.keys()):
if d < st:
del(self.shown[d])
else:
d = self.shown[d]
# xpos + cos(radius)
# ypos + sin(radius)
render.blit(d.render(width, height, st, at),(self.around[0] + d.radius * math.cos(d.angle), d.around[1] + d.radius * math.sin(d.angle)))
rp.redraw(self, 0)
return render
def visit(self):
return self.d
image bubble_pic = Transform("bubble.png",zoom=0.1)
init python:
def bubble_func():
return BubbleShoot("bubble_pic",interval=(0.03,0.05), keep_time = (3.0,5.0), around = (960,540), angle=(0,360), radius=(200,250), particles=30)
screen bubble_button_v2:
predict False
default show_sm = False
if show_sm:
add bubble_func()
# 按钮(放在屏幕下方中央)
textbutton "✨ 点我冒泡泡":
xalign 0.5
yalign 0.5
text_align (0.5,0.5)
action SetScreenVariable("show_sm",False),SetScreenVariable("show_sm",True)
background Solid("#4CAF50", xsize=200, ysize=60)
text_color "#fff"
text_size 24
hover_background Solid("#1a28a3", xsize=200, ysize=60)
label bubbleV2:
show screen bubble_button_v2
"点击屏幕上方的按钮,看看泡泡特效!"
"1"
hide screen bubble_button_v2
return
|
评分
-
查看全部评分
|