JavaFX中如何实现打字机效果?

发布于 2024-09-08 18:18:08 字数 91 浏览 1 评论 0原文

我想逐个字母打印更长的文本 - 就像有人只是在打字机上打字一样。 JavaFX 中最好的方法是什么?

I'd like to print a longer text letter by letter - as if someone is just typing it on a typewriter. What's the best approach here in JavaFX?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过潦 2024-09-15 18:18:08

您只需要获取一个字符串,然后将其逐个字母地放置到场景中即可模拟打字机打字。
迭代字符串并可能增加当前字母的 x,y 位置以使其在屏幕上就位。
查看 JavaFX 1.3 api 中的 TimeLine 对象,在每个在时间线上“打勾”,您可以写一封新信。
一个小的随机延迟将使布局看起来更像打字(看看 PauseTransition - 它在给定的延迟后执行一个操作 - 这可以绑定到在每个刻度处随机设置的 var)。

希望这有帮助。当你让它工作时,请随意将其发布回此处或类似 jfxstudio.org 的地方。

You'll just need to take a string and then lay it out letter-by-letter on to the scene to simulate a typewriter typing.
Iterate over the string and maybe increment an x,y position of the current letter to get it in place on the screen.
Take a look at the TimeLine object in the JavaFX 1.3 api, at each "tick" of the timeline you can write a new letter out.
A small random delay will make the layout appear more like typing (look at PauseTransition - which executes an action after a given delay - this could be bound to a var set randomly at each tick).

Hope this helps. Feel free to post it back here or to somewhere like jfxstudio.org when you get it working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文