-
Notifications
You must be signed in to change notification settings - Fork 0
The life cycle
A libgdx application has a well defined life-cycle, governing the states of an application, like creation, pausing and resuming, rendering and disposing the application.
An application developer hooks into these life-cycle events by implementing the ApplicationListener interface and passing an instance of that implementation to the Application
implementation of a specific back-end (see The Application Framework). From there on, the Application
will call the ApplicationListener
every time an application level event occurs. A bare-bones ApplicationListener
implementation may look like this:
public class MyGame implements ApplicationListener {
public void create () {
}
public void render () {
}
public void resize (int width, int height) {
}
public void pause () {
}
public void resume () {
}
public void dispose () {
}
}
One can also derive from the ApplicationAdapter class if not all interface methods are of relevance.
Once passed to the Application
, the ApplicationListener
methods will be called as follows:
Method signature | Description |
---|---|
create () |
Method called once when the application is created. |
resize(int width, int height) |
This method is called every time the game screen is re-sized and the game is not in the paused state. It is also called once just after the create() method.The parameters are the new width and height the screen has been resized to in pixels. |
render () |
Method called by the game loop from the application every time rendering should be performed. Game logic updates are usually also performed in this method. |
pause () |
On Android this method is called when the Home button is pressed or an incoming call is received. On desktop this is called just before dispose() when exiting the application.A good place to save the game state. |
resume () |
This method is only called on Android, when the application resumes from a paused state. |
dispose () |
Called when the application is destroyed. It is preceded by a call to pause() . |
The following diagram illustrates the life-cycle visually:
Libgdx is event driven by nature, mostly due to the way Android and JavaScript work. An explicit main loop does not exist, however, the ApplicationListener.render()
method can be regarded as the body of such a main loop.
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics ?? * Quick Start * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- gdx-audio ??
- gdx-freetype
- Deploying your Application
- Building Libgdx ??
- Articles
- Deprecated (May be outdated)
- The Application Framework
- The Application Life-cycle ??
- Modules Overview
- File Module
- Graphics Module
- Asset Manager
- Tutorials
- Video Tutorials
- Beginner * Hello World * My First Triangle * Mesh, Color & Texture * Projection, Viewport, & Camera * Creating and texturing 3d models in Blender for Libgdx
- Intermediate * Actions
- Misc * AdMob in Libgdx * Integrating Libgdx and the Device camera * String Builder ??
- The Application Framework