Game Development Reference
In-Depth Information
We have a couple of members again holding a camera, a SpriteBatcher , the rectangle for the
arrow button, a vector for the touch point, and a Texture and a TextureRegion for the help image.
public HelpScreen(Game game) {
super (game);
guiCam = new Camera2D(glGraphics, 320, 480);
nextBounds = new Rectangle(320 - 64, 0, 64, 64);
touchPoint = new Vector2();
batcher = new SpriteBatcher(glGraphics, 1);
}
In the constructor, we set up all members pretty much the same way we did in the
MainMenuScreen .
@Override
public void resume() {
helpImage = new Texture(glGame, "help1.png" );
helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
}
@Override
public void pause() {
helpImage.dispose();
}
In the resume() method, we load the actual help screen texture and create a corresponding
TextureRegion for rendering with the SpriteBatcher . We do the loading in this method, as the
OpenGL ES context might be lost. The textures for the background and the UI elements are
handled by the Assets and SuperJumper classes, as discussed before. We don't need to deal
with them in any of our screens. Additionally, we dispose of the help image texture in the pause()
method again to clean up memory.
@Override
public void update( float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
game.getInput().getKeyEvents();
int len = touchEvents.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (event.type == TouchEvent. TOUCH _ UP ) {
if (OverlapTester. pointInRectangle (nextBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
game.setScreen( new HelpScreen2(game));
return ;
}
}
}
}
Search WWH ::




Custom Search