我正在研究使用缓冲区策略和 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 应用程序中,我们不需要担心将调用
show
放在 EDT 上吗? - 其他人可以在 Swing 应用程序中看到任何问题吗?
这是受到游戏编程这个有趣答案的启发。