最有效的文本缓动方式是什么
2021-3-1 19:42:30
收藏:0
阅读:117
评论:1
我想知道如何缓动文本,并且最有效的缓动方式是什么,我考虑使用Tween Service,但它只能缓动数字值,因此不可能对字符串进行缓动,我可以明显地按顺序添加每个字母,但是用这种方法制作段落需要花费一定时间,所以我需要一种有效且可行的方法来完成这个任务,以下是我尝试使用Tween Service的代码:
local serv = game:GetService("TweenService")
local start = script.Parent.TextLabel
local stop = {}
stop.Text = "hi there lol this is just a test"
local info = TweenInfo.new(5, Enum.EasingStyle.Sine)
local play = serv:Create(start, info, stop)
while true do
wait(5)
play:Play()
end
我知道这不起作用,但我还是尝试了一下。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

正如你所发现的,你不能直接 tween 文本。Tween 是设计用来获取开始点和结束点并填补这两点之间的差距,但对于文本来说,不太清楚应该如何做到这一点。如果你的起点是“hello”,终点是“goodbye”,那么到达那里的步骤又是什么呢?
但如果你想要制作经典的打字机动画,你可以很容易地逐个字母地对文本进行动画处理。
这涉及循环整个文本消息并且每次取一些子字符串。这将使得每次动画更新时都会添加一个字母的外观。使用一些数学和 TweenService:GetValue,我们可以插值出动画的进度。
因此,请尝试以下内容:
local TweenService = game:GetService("TweenService") local function writeText(targetLabel, text, duration, easingStyle, easingDirection) -- 校验输入 local numLetters = #text if numLetters == 0 then targetLabel.Text = "" return end if easingStyle == nil then easingStyle = Enum.EasingStyle.Linear end if easingDirection == nil then easingDirection = Enum.EasingDirection.InOut end local startingTime = tick() local letterCount = 0 while letterCount < numLetters do -- 计算动画进行的进度 local timePassed = (tick() - startingTime) local percentDone = TweenService:GetValue(timePassed / duration, easingStyle, easingDirection) letterCount = math.ceil(percentDone * numLetters) local message = string.sub(text, 1, letterCount) -- 更新文本 targetLabel.Text = message -- 等待以便动画播放 wait(0.05) end end -- 测试 local lbl = script.Parent.TextLabel local msg = "hi there lol this is just a test, it can be really long too." local duration = 5 --seconds local style = Enum.EasingStyle.Sine local direction = Enum.EasingDirection.InOut writeText(lbl, msg, duration, style, direction)