Java3D获取时间问题

发布于 2024-08-26 02:01:53 字数 343 浏览 4 评论 0原文

我制作了一个小型射击游戏,其中两艘船互相射击。我使用paintComponent的方法来绘制或移动对象,但由于某种原因它在每台计算机上以不同的速度运行。

我寻找解决方案并对我的游戏进行了一些修改,例如在线程中绘制和移动对象。现在它在每台计算机上以相同的速度运行。如果我改变尺寸也是如此。但问题是我使用了 J3DTimer.getValue()。

为了使用这个库,我下载了 Java3d。如果计算机没有这个库或安装,我的游戏将无法运行。我该如何解决这个问题?我应该告诉大家安装Java##吗? :))

我还尝试使用标准 System.currentTimeMillis(),但是我的游戏运行速度非常慢......有什么想法吗?

I made a little Shooter game with two ships firing at each other. I used methods of paintComponent for drawing or moving object, but for some reason it ran at a different speed on each computer.

I searched for a solution and made some modifications to my game like drawing and moving objects in thread. Now it runs at the same speed on every сomputer. Also if I change size. But the problem is I used J3DTimer.getValue().

To use this library I downloaded Java3d. If the computer does not have this library or installation my game does not work. How can I solve this problem? Should I tell everyone to setup Java##? :))

Also I tried using standard System.currentTimeMillis(), but then my game works very slow... Any ideas?

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

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

发布评论

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

评论(1

孤檠 2024-09-02 02:01:53

从Java 1.5开始,出现了一种名为System.nanoTime()的方法,它通常比System.currentTimeMillis()精确得多(取决于底层硬件的能力) )。

我认为 System.nanoTime() 应该是 J3DTimer.getValue() 的直接替代品。这样您就可以消除对 Java3D 库的依赖。

Since Java 1.5 there has been a method called System.nanoTime(), which is generally much more precise than System.currentTimeMillis() (depending on the capabilities of the underlying hardware).

I think System.nanoTime() should be a drop-in replacement for J3DTimer.getValue(). That way you remove your dependency on the Java3D library.

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