我正在考虑使用缓冲策略以及 Javadoc 中描述的以下技术:
// Main loop
while (!done) {
// Prepare for rendering the next frame
// ...
// Render single frame
do {
// The following loop ensures that the contents of the drawing buffer
// are consistent in case the underlying surface was recreated
do {
// Get a new graphics context every time through the loop
// to make sure the strategy is validated
Graphics graphics = strategy.getDrawGraphics();
// Render to graphics
// ...
// Dispose the graphics
graphics.dispose();
// Repeat the rendering if the drawing buffer contents
// were restored
} while (strategy.contentsRestored());
// Display the buffer
strategy.show();
// Repeat the rendering if the drawing buffer was lost
} while (strategy.contentsLost());
}
最好避免EDT and invokeLater
or invokeAndWait
执行动画时。
我的问题:
- 如果这是在 Swing 应用程序中,我们不需要担心调用
show
在美国东部时间?
- 其他人能看到在 Swing 应用程序中使用它有任何问题吗?
这是受此启发有趣的答案到游戏编程。
一般来说,没有。在除线以外的线上绘画事件调度线程 (EDT)尽管结果可能是可以接受的,但会导致不良的伪影。这example展示了一些权衡。我更喜欢安排在 EDT 上使用javax.swing.Timer, but 其他方法是可能的。另外,您选择的顶级容器可能已经实施了缓冲策略.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)