In the examples in the last two chapters, we always got the reference to GLGraphics by casting. Let's fix this with a little helper class called GLScreen, which will do the dirty work for us and store the reference to GLGraphics in a member. Listing 9-5 shows the code.

Listing 9-5., a Little Helper Class package com.badlogic.androidgames.framework.impl;

import com.badlogic.androidgames.framework.Game; import com.badlogic.androidgames.framework.Screen;

public abstract class GLScreen extends Screen { protected final GLGraphics glGraphics; protected final GLGame glGame;

public GLScreen(Game game) { super(game); glGame = (GLGame)game;

glGraphics = ((GLGame)game).getGLGraphics();

We store the GLGraphics and GLGame instances. Of course, this will crash if the Game instance passed as a parameter to the constructor is not a GLGame. But we'll make sure it is. All the screens of Super Jumper will derive from this class.

0 0

Post a comment