萝卜说 - 罗布乐思 - 口袋核心

查看: 685|回复: 0

[讨论] 对话文字显示,实现一个字一个字显示

[复制链接]

3

收听

0

听众

57

帖子

正式用户

Rank: 1

萝卜币
108
发表于 2021-5-31 13:11:58 | 显示全部楼层 |阅读模式
这个功能可自行封装在moudle中,可以运用在需要进行对话的游戏,代码比较简单好学。
local a = true --防止多次执行该函数导致重复显示
local seep = 0.3 --文字显示速度
function dh(UiText,text)
    if a == true then
            a = false
            UiText.Text = ''
            local i = 1

            while true do
                    wait(seep)
                    local c = string.sub(text,i,i)
                     local b = string.byte(c)

                    if b > 128 then
                            UiText.Text = UiText.Text .. string.sub(text,i,i+2)
                            i = i + 3
                    else
                            if b == 32 then
                                    UiText.Text = UiText.Text .. ' '
                            else
                                    UiText.Text = UiText.Text .. c
                            end
                             i = i + 1
                    end

                    if i > #text then
                            break
                    end
            end       
            a = true
    end
end

--实例
local ui = script.Parent --这是一个带有Text属性的文本
dh(ui,"我是一段比较长的文字..........")
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋| |京公网安备11010502045240号

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.4  备案:京ICP备2021013067号-2

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