- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JavaFX 的 AnimationTimer
启动时是否在单独的线程上运行?
我在调试器中运行了一个 JavaFX 应用程序,无论有没有 AnimationTimer
,在这两种情况下都有 6 个线程在运行。另外,JavaDocs 没有提到它实现 Runnable
。
这表明它不是在自己的线程中运行,但就其本质而言,我认为它需要在自己的线程中运行以确保它按足够规律的时间表运行。
如果它不在自己的线程中运行,它是否只是在创建它的线程中运行?这是否意味着如果我在 Application
的 start()
内部创建 AnimationTimer
,可以安全地从 Timer 内修改 UI 元素?
最佳答案
Does JavaFX's AnimationTimer run on a separate thread when launched?
不,事实并非如此。它在 JavaFX 应用程序线程上运行。当 AnimationTimer 处于事件状态时,在每一帧中都会调用 AnimationTimer 的 handle()
方法。通常,JavaFX 会尝试保持 60 fps 的帧速率。
Does that mean it's safe to modify UI elements from within the Timer if I create the AnimationTimer inside of Application's start()?
是的,确实如此。由于它在 JavaFX 应用程序线程上运行,因此修改场景图元素是完全可以的。只需确保您没有在 handle()
中进行大量计算即可。
关于javafx - AnimationTimer 是否在自己的线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068953/
这是引自 AnimationTimer类文档。 The class AnimationTimer allows to create a timer, that is called in each fr
所以,我正在使用 JavaFX 创建贪吃蛇游戏,但我似乎无法使游戏正确暂停,即它偶尔会暂停,而其他时候,游戏只是忽略暂停。所以,基本上我有一个 Main 类,我在其中初始化所有 GUI 组件,并且它还
JavaFX 的 AnimationTimer 启动时是否在单独的线程上运行? 我在调试器中运行了一个 JavaFX 应用程序,无论有没有 AnimationTimer,在这两种情况下都有 6 个线程
所以,我正在使用 JavaFX 创建贪吃蛇游戏,但我似乎无法使游戏正确暂停,即它偶尔会暂停,而其他时候,游戏只是忽略暂停。所以,基本上我有一个 Main 类,我在其中初始化所有 GUI 组件,并且它还
当玩家赢得我创建的游戏时,我试图显示一个警报对话框。但是,我遇到了一个异常(exception): java.lang.IllegalStateException: showAndWait is no
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我目前正在开发一款使用 JavaFX 制作的游戏,我想知道如何将 AnimationTimer 暂停一定的秒数?我尝试使用 Thread.sleep,但它会导致整个窗口卡住。任何帮助将不胜感激,如果需
我知道可以使用 this.stop 函数从其覆盖的 handle() 方法中停止正在进行的动画。下面的代码来自游戏,在游戏获胜并显示警报后,它应该停止运行动画。相反,警报会弹出无数次。 new Ani
我已经编写了一个简单的游戏,使用 JavaFX 作为 GUI 并使用 AnimationTimer 作为游戏本身,但我发现在 AnimationTimer 对象内更新的任何字段都无法在该对象外部找到。
我将 AnimationTimer 用于多个任务,例如带有不断变化的图片的动画和 ProgressIndicator 动画。为了达到所需的速度,我将线程置于 hibernate 状态,但是当多个动画同
我正在尝试向地球绕太阳运行的小动画添加一个“开始”按钮。我的问题是,当我单击按钮时,AnimationTimer 似乎从未收到 start() 调用。 当单击按钮的事件被触发时,动画计时器应该启动,从
考虑这段代码: import java.util.ArrayDeque; import javafx.animation.AnimationTimer; import javafx.animation
我有一个用 JavaFX 编写的俄罗斯方 block 游戏。我想把它翻译成C++来学习C++。我可以在 C++ 中使用什么来显示图形并为游戏循环计时,就像我使用 JavaFX 和 AnimationT
我正在尝试制作一个游戏,其中我有类矩形的障碍,并让它左右滑动。然而,虽然看起来应该可以工作,但我命名为障碍物 1 的矩形却没有任何移动。 import javafx.animation.Animati
我是一名优秀的程序员,十分优秀!