我目前正在使用libgdx开发一个简单的游戏。我正在使用FrameBuffers渲染游戏中的屏幕过渡。该代码正常工作正常。处理屏幕过渡的代码是这样的(它在主游戏类中):
@Override
public void render () {
float delta = Gdx.graphics.getDeltaTime();
if (nextScreen == null) { // no transition
if (currentScreen != null) {
currentScreen.render(delta);
}
} else {
transitionInProgress = true;
transitionTime = Math.min(transitionTime + delta, getTransitionDuration());
// render to texture only once for performance
if (!renderedToTexture) {
renderScreensToTexture();
renderedToTexture = true;
}
// update transitions
updateTransitions();
}
}
private void updateTransitions() {
// transition just finished or no transition is specified
if (screenTransition == null || transitionTime >= getTransitionDuration()) {
if (currentScreen != null) {
currentScreen.hide();
if (nextScreen != null && !(nextScreen instanceof BaseOverlay)) currentScreen.dispose(); // don't dispose the current screen if next screen is instance of BaseOverlay
}
// resume next screen
if (nextScreen != null) {
nextScreen.resumeLogic();
Gdx.input.setInputProcessor(nextScreen.getInputProcessor());
}
// switch screens and reset
currentScreen = nextScreen;
nextScreen = null;
screenTransition = null;
currentFrameBuffer.dispose();
nextFrameBuffer.dispose();
currentFrameBuffer = null;
nextFrameBuffer = null;
renderedToTexture = false;
transitionInProgress = false;
return;
}
float percentage = transitionTime / getTransitionDuration();
Gdx.app.log(TAG, "updateTransitions: " + percentage);
// the textures are auto disposed when the frame buffer objects are disposed
Texture currentScreenTexture = currentFrameBuffer.getColorBufferTexture(), nextScreenTexture = nextFrameBuffer.getColorBufferTexture();
// render transition to screen
transitionSpriteBatch.setProjectionMatrix(transitionViewport.getCamera().combined);
screenTransition.render(transitionSpriteBatch, currentScreenTexture, nextScreenTexture, percentage);
}
private void renderScreensToTexture() {
if (currentScreen != null) {
currentFrameBuffer.begin();
currentScreen.render(0); // 0 to render first frame
currentFrameBuffer.end();
}
if (nextScreen != null) {
nextFrameBuffer.begin();
nextScreen.render(0);
nextFrameBuffer.end();
}
}
问题是这样的:过渡不适用于我的屏幕覆盖。我仅通过使用在其render方法中渲染前一个屏幕的屏幕来实现屏幕覆盖。但是一旦开始过渡,叠加层就可以进行完美的过渡,但是下面的屏幕根本无法渲染。我认为这与FrameBuffers有关,但是我最近才了解它们,所以我了解的不多。有什么解决方案?
这是我的屏幕覆盖的代码:
@Override
public void render(float delta) {
super.render(delta);
prevScreen.render(delta); // render the previous screen
screenUI.renderUI();
}