Game.java :  » Game » libgdx » com » badlogic » gdx » Android Open Source

Android Open Source » Game » libgdx 
libgdx » com » badlogic » gdx » Game.java
/*
 * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.badlogic.gdx;

/**
 * <p>
 * An {@link ApplicationListener} that delegates to a {@link Screen}. This allows an application to easily have multiple screens.
 * </p>
 * <p>
 * Screens are not disposed automatically. You must handle whether you want to keep screens around or dispose of them when another
 * screen is set.
 * </p>
 */
public abstract class Game implements ApplicationListener {
  private Screen screen;

  @Override public void dispose () {
    if (screen != null) screen.hide();
  }

  @Override public void pause () {
    if (screen != null) screen.pause();
  }

  @Override public void resume () {
    if (screen != null) screen.resume();
  }

  @Override public void render () {
    if (screen != null) screen.render(Gdx.graphics.getDeltaTime());
  }

  @Override public void resize (int width, int height) {
    if (screen != null) screen.resize(width, height);
  }

  /**
   * Sets the current screen. {@link Screen#hide()} is called on any old screen, and {@link Screen#show()} is called on the new
   * screen.
   */
  public void setScreen (Screen screen) {
    if (this.screen != null) this.screen.hide();
    this.screen = screen;
    screen.show();
    screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  }

  /**
   * @return the currently active {@link Screen}.
   */
  public Screen getScreen () {
    return screen;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.