【发布时间】:2009-12-27 18:54:04
【问题描述】:
我正在研究使用 Buffer Strategy 和 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 和invokeLater 或invokeAndWait。
我的问题:
- 如果这是在 Swing 应用程序中,我们不需要担心在 EDT 上调用
show吗? - 其他人可以看到在 Swing 应用程序中使用它有什么问题吗?
这是受到interesting answer 游戏编程的启发。
【问题讨论】:
标签: java swing animation event-dispatch-thread