Java3D获取时间问题
我制作了一个小型射击游戏,其中两艘船互相射击。我使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从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 thanSystem.currentTimeMillis()
(depending on the capabilities of the underlying hardware).I think
System.nanoTime()
should be a drop-in replacement forJ3DTimer.getValue()
. That way you remove your dependency on the Java3D library.