Game Development Reference
In-Depth Information
if (currScreen != null) currScreen.hide();
if (nextScreen != null) nextScreen.hide();
if (init) {
currFbo.dispose();
currScreen = null;
nextFbo.dispose();
nextScreen = null;
batch.dispose();
init = false;
}
}
The preceding code ensures that the current and the next screens will be informed
about the occurring events and that the screens, the sprite batch, and the FBOs will
be correctly disposed off when they are no longer needed.
As a last step, we now want to rewire some parts of Canyon Bunny to use the added
screen transition capability, which we just implemented. Therefore, we are going to
make some minor modifications in those places where we are still using LibGDX's
Game class and replace it with our own class, DirectedGame .
Add the following import line to AbstractGameScreen :
import com.badlogic.gdx.InputProcessor;
After this, add the following line to the same class:
public abstract InputProcessor getInputProcessor ();
Next, make the following changes to the same class:
protected DirectedGame game;
public AbstractGameScreen (DirectedGame game) {
this.game = game;
}
These changes introduce a new method called getInputProcessor() ,which also
needs to be implemented in MenuScreen and GameScreen . This is necessary to
allow DirectedGame to route and control the flow of input processing as needed.
As mentioned earlier, this will avoid any interference with the user input during a
running transition.
Now, add the following import line to CanyonBunnyMain :
import com.packtpub.libgdx.canyonbunny.screens.DirectedGame;
 
Search WWH ::




Custom Search