找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 893|回复: 0

[原创] 打字效果(Typewriter Effect)

[复制链接]
发表于 2023-10-22 01:03:05 | 显示全部楼层 |阅读模式

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

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

×



具体讲解请看视频,代码如下。

[RenPy] 纯文本查看 复制代码
init python:
    def tw_sfx(event, **kwargs):
        if event == "show":
            renpy.music.play("audio/typewriter.mp3", channel="sound",  loop=True)
        elif event == "slow_done" or event == "end":
            renpy.music.stop(channel="sound")

image ctc_blink:
    Solid("#0ff")
    xysize (10, 20)
    linear 0.5 alpha 1.0
    linear 0.5 alpha 0.0
    repeat

define tw = Character("tw", who_color="#c8ffc8", callback=tw_sfx, 
    ctc="ctc_blink", ctc_position="nestled")
define e = Character("Eileen", who_color="#f479c1")

## 制作者:b站 黑凤梨BlackPineappl
## [url]https://space.bilibili.com/628485868[/url]

label start:
    scene bg bedroom

    show expression Text("反派大小姐选择重开",color="#020202", size=60, xalign=0.5,yalign=0.23,slow_cps=8)

    pause
    
    "{cps=20}固定速度{/cps} {cps=*2}两倍速{/cps}"

    $ preferences.text_cps = 5
    tw "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
    pause
    tw "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"

    
    $ preferences.text_cps = 0

    e "test"
    $ preferences.text_cps = 5
    tw "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"

    return



UDD版本,作者 被诅咒的章鱼
[RenPy] 纯文本查看 复制代码
image point:
    Solid("#0ff")
    xysize(10, 30)
    linear 0.2 alpha 1.0
    linear 0.2 alpha 0.0
    repeat

init python:
    
    test_text = "文本显示测试。文本显示测试。文本显示测试。文本显示测试。文本显示测试。文本显示测试。文本显示测试。文本显示测试。"

    typer_hint = "point"

    def get_text_with_typer_hint(str, typer_hint):
        return str + "{image=" + typer_hint + "}"

    class TyperText(renpy.Displayable):
        def __init__(self, child, typer_gap, typer_hint, **kwargs):
            super(TyperText, self).__init__(**kwargs)
            self.child = Text(child)
            self.all_text = child.get_all_text()
            self.typer_gap = typer_gap
            self.typer_hint = typer_hint
        
        def render(self, width, height, st, at):
            end_str_index = min( int(st / self.typer_gap), len(self.all_text))
            sub_str = self.all_text[0:end_str_index] + "{image=" + self.typer_hint + "}"
            self.child.set_text(sub_str)
            t = Transform(child=self.child)
            child_render = renpy.render(t, width, height, st, at)
            self.width, self.height = child_render.get_size()
            render = renpy.Render(self.width, self.height)
            render.blit(child_render, (0, 0))
            renpy.redraw(self, 0)

            return render

image grey = "#5f5f5f"

screen text_typer_screen:
    add TyperText(Text(test_text), 0.5, typer_hint)


# label main_menu:
#     return


## 代码作者:被诅咒的章鱼
## 教程制作者:b站 黑凤梨BlackPineappl
## [url]https://space.bilibili.com/628485868[/url]
label start:

    scene grey

    "......"
    play music "audio/typewriter.mp3" loop
 
    call screen text_typer_screen
    
    "......"
    
    
    return
    



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

本版积分规则

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

GMT+8, 2024-12-22 19:29 , Processed in 0.149150 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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