libgdx API

com.badlogic.gdx
Interface Application

All Known Implementing Classes:
AndroidApplication, JoglApplication, LwjglApplication, LwjglCanvas

public interface Application

An Application is the main entry point of your project. It sets up a window and rendering surface and manages the different aspects of your application, namely Graphics, Audio, Input and Files. Think of an Application being equivalent to a JFrame of Activity.

An application can either be a desktop application JoglApplication, LwjglApplication found in gdx-backends-jogl.jar and gdx-backends-lwjgl.jar respectively), or an Android application AndroidApplication found in gdx-backends-android.jar). Each application class has it's own startup and initialization methods. Please refer to their documentation for more information.

While game programmers are used to having a main loop, libgdx employs a different concept to accomodate the event based nature of Android applications a little more. You application logic must be implemented in a ApplicationListener which has methods that get called by the Application when the application is created, resumed, paused, disposed or rendered. As a developer you will simply implement the ApplicationListener interface and fill in the functionality accordingly. The ApplicationListener is provided to a concrete Application instance as a parameter to the constructor or another initialization method. Please refer to the documentation of the Application implementations for more information. Note that the ApplicationListener can be provided to any Application implementation. This means that you only need to write your program logic once and have it run on different platforms by passing it to a concrete Application implementation.

The Application interface provides you with a set of modules for graphics, audio, input and file i/o.

Graphics offers you various methods to output visuals to the screen. This is achieved via OpenGL ES 1.0, 1.1 or 2.0 depending on what's available an the platform. On the desktop the features of OpenGL ES 2.0 are emulated via desktop OpenGL. On Android the functionality of the Java OpenGL ES bindings is used.

Audio offers you various methods to output and record sound and music. This is achieved via the Java Sound API on the desktop. On Android the Android media framework is used.

Input offers you various methods to poll user input from the keyboard, touch screen, mouse and accelerometer. Additionally you can implement an InputProcessor and use it with Input.setInputProcessor(InputProcessor) to receive input events.

Files offers you various methods to access internal and external files. An internal file is a file that is stored near your application. On Android internal file are equivalent to assets. On the desktop the classpath is first scanned for the specified file. If that fails then the root directory of your application is used for a look up. External files are resources you create in your application and write to an external storage. On Android external files reside on the SD-card, on the desktop external files are written to a users home directory. If you know what you do you can also specify absolute file names. This is not portable, so take great care when using this feature.

The Application also has a set of methods that you can use to query specific information such as the operating system the application is currently running on and so forth. This allows you to have operating system dependent code paths. It is however not recommended to use this facilities.

The Application also has a simple logging method which will print to standard out on the desktop and to logcat on Android.

Author:
mzechner

Nested Class Summary
static class Application.ApplicationType
          Enumeration of possible Application types
 
Field Summary
static int LOG_ERROR
           
static int LOG_INFO
           
static int LOG_NONE
           
 
Method Summary
 void error(java.lang.String tag, java.lang.String message)
          Logs an error message to the console or logcat
 void error(java.lang.String tag, java.lang.String message, java.lang.Exception exception)
          Logs an error message to the console or logcat
 void exit()
          Exits the application.
 Audio getAudio()
           
 Files getFiles()
           
 Graphics getGraphics()
           
 Input getInput()
           
 long getJavaHeap()
           
 long getNativeHeap()
           
 Preferences getPreferences(java.lang.String name)
          Returns the Preferences instance of this Application.
 Application.ApplicationType getType()
           
 int getVersion()
           
 void log(java.lang.String tag, java.lang.String message)
          Logs a message to the console or logcat
 void log(java.lang.String tag, java.lang.String message, java.lang.Exception exception)
          Logs a message to the console or logcat
 void postRunnable(java.lang.Runnable runnable)
          Posts a Runnable on the main loop thread.
 void setLogLevel(int logLevel)
          Sets the log level.
 

Field Detail

LOG_NONE

static final int LOG_NONE
See Also:
Constant Field Values

LOG_INFO

static final int LOG_INFO
See Also:
Constant Field Values

LOG_ERROR

static final int LOG_ERROR
See Also:
Constant Field Values
Method Detail

getGraphics

Graphics getGraphics()
Returns:
the Graphics instance

getAudio

Audio getAudio()
Returns:
the Audio instance

getInput

Input getInput()
Returns:
the Input instance

getFiles

Files getFiles()
Returns:
the Files instance

log

void log(java.lang.String tag,
         java.lang.String message)
Logs a message to the console or logcat


log

void log(java.lang.String tag,
         java.lang.String message,
         java.lang.Exception exception)
Logs a message to the console or logcat


error

void error(java.lang.String tag,
           java.lang.String message)
Logs an error message to the console or logcat


error

void error(java.lang.String tag,
           java.lang.String message,
           java.lang.Exception exception)
Logs an error message to the console or logcat


setLogLevel

void setLogLevel(int logLevel)
Sets the log level. LOG_NONE will mute all log output. LOG_ERROR will only let messages issued with error(String, String) through. LOG_INFO will let all messages though, either logged via error(String, String) or log(String, String).

Parameters:
logLevel - LOG_NONE, LOG_ERROR, LOG_INFO.

getType

Application.ApplicationType getType()
Returns:
what Application.ApplicationType this application has, e.g. Android or Desktop

getVersion

int getVersion()
Returns:
the Android API level on Android or 0 on the desktop.

getJavaHeap

long getJavaHeap()
Returns:
the Java heap memory use in bytes

getNativeHeap

long getNativeHeap()
Returns:
the Native heap memory use in bytes

getPreferences

Preferences getPreferences(java.lang.String name)
Returns the Preferences instance of this Application. It can be used to store application settings across runs.

Parameters:
name - the name of the preferences, must be useable as a file name.
Returns:
the preferences.

postRunnable

void postRunnable(java.lang.Runnable runnable)
Posts a Runnable on the main loop thread.

Parameters:
runnable - the runnable.

exit

void exit()
Exits the application. This will cause a call to pause() and dispose() some time in the loadFuture, it will not immediately finish your application!


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)