Game Development Reference
In-Depth Information
public void render (SpriteBatch batch, Texture currScreen,
Texture nextScreen, float alpha);
}
The preceding interface allows us to query the duration of a transition effect and
enables us to let it render its effect using two supplied textures that contain the
images of the current and the next screens. In addition to this, the alpha value is used
to describe the current state of progress of the transition effect that is to be rendered.
Using an alpha value of 0.0, for example, will render the effect at the very beginning
while a value of say, 0.25, will render it when the effect has progressed to 25 percent.
You might wonder why the render() method takes two instances of Texture
instead of AbstractGameScreen . This is because, in general, a transition effect
should not depend on the contents of the screens that it is working with. Therefore,
both the screens, the current and the next one, need to be transformed into two
self-contained units. This can be achieved by rendering each screen to its own
in-memory texture. This technique is also known as RTT.
OpenGL has a feature called Framebuffer Objects ( FBO ) that allows this kind
of offscreen rendering to textures present in memory. FBOs can be used by
instantiating new objects of LibGDX's Framebuffer class.
The following is an example of how FBOs should be used in general:
// ...
Framebuffer fbo;
fbo = new Framebuffer(Format.RGB888, width, height, false);
fbo.begin(); // set render target to FBO's texture buffer
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // solid black
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // clear FBO
batch.draw(someTextureRegion, 0, 0); // draw (to FBO)
fbo.end(); // revert render target back to normal
// retrieve result
Texture fboTexture = fbo.getColorBufferTexture();
// ...
A new FBO is initialized by passing in a format, a width and a height, and a flag
indicating whether an attached depth buffer is needed. The passed format and
dimensions are used to initialize the FBO's texture that will serve as its render
target. The flag for the depth buffer, also referred to as the Z-buffer, enables the
sorting of pixels in a three-dimensional space. Since we are creating a game in a two-
dimensional space and also have taken care of the rendering order by ourselves,
there is no need to enable this buffer, which would just waste precious memory.
 
Search WWH ::




Custom Search