public final class Game
extends java.lang.Object
The Game class is without any doubt one of the classes that you will call a lot when creating a game with the LITIengine.
It is designed to be the static container that provides access to all important aspects of the engine, e.g. it holds the GameInfo,
the RenderEngine, the SoundEngine and many other major components.
We designed the API such that all important parts that make up the game are directly accessible via the Game class in a static manner.
To be a little bit more technical, it is essentially a collection of core Singleton instances.
This class will also be your starting point when setting up a new LITIengine project. In order to launch your game,
you need to at least call init(String...) and start() from your programs main(String[]) method.
Additionally, it provides an interface to hook up event listeners (e.g. GameListener or EnvironmentLoadedListener) for
the most basic operations of a Game life cycle.
GameListener| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COMMADLINE_ARG_NOGUI |
static java.lang.String |
COMMADLINE_ARG_RELEASE |
static int |
EXIT_GAME_CLOSED |
static int |
EXIT_GAME_CRASHED |
| Modifier and Type | Method and Description |
|---|---|
static void |
addGameListener(GameListener listener)
Adds the specified game listener to receive events about the basic game life-cycle.
|
static void |
allowDebug(boolean allow)
This flag indicates if the game currently supports debugging.
|
static SoundEngine |
audio()
Gets the engine's
SoundEngine component that can be used to play sounds and music.Sound can be loaded and accessed using the Resources API and are managed by theResources.sounds() resource container. |
static GameConfiguration |
config()
Gets the game's runtime configuration.
It contains default engine settings for the game client, graphics, audio, input and debugging. Additionally, it can be used to register and manage custom settings that are specific to your game. |
static RenderEngine |
graphics()
Gets the engine's
RenderEngine component that is used to render Images, Shapes or Text with respect to the environment
and the render scale and the Camera. |
static boolean |
hasStarted()
Indicates whether the game has already been started.
|
static void |
hideGUI(boolean noGui)
This flag indicates whether the game should display the
GameWindow or not. |
static GameInfo |
info()
Gets the static meta information about this game.
This can be used to define meta information about your game, like it's name, version or web site. It's also possible to provide additional custom information using the method group Game.getInfo().setValue("CUSTOM_STRING", "my-value"). |
static void |
init(java.lang.String... args)
Initializes the infrastructure of the LITIengine game.
|
static ILoop |
inputLoop()
Gets the game's input loop that processes all the player input.
|
static boolean |
isDebug()
This flag globally controls the game's debugging state.
|
static boolean |
isInNoGUIMode()
Indicates whether the game should display the
GameWindow or not. |
static java.util.logging.Logger |
log()
Gets the game's default logger instance that can be used to quickly log messages without the need to initialize
custom logger instances.
|
static IGameLoop |
loop()
Gets the game's main loop that is used to execute and manage all game logic apart from input processing.
You can attach any Updatable instance to this loop if you want to execute custom game logic that is executed at the configured
max fps. |
static GameMetrics |
metrics()
Gets basic client metrics about the game's runtime.
|
static PhysicsEngine |
physics()
Gets the engine's
PhysicsEngine component that can be used to detect and resolve collision and move entities with respect to all
collision
entities on the environment.The boundaries of the loaded environment also pose a "non-walkable" area that will be taken into account when moving entities with this engine. |
static void |
removeGameListener(GameListener listener)
Removes the specified game listener.
|
static ScreenManager |
screens()
Gets the game's
ScreenManager that is responsible for organizing all Screens of your game and providing the currently
active Screen that is used to render the current Environment.Screens are the containers that allow you to organize the visible contents of your game and are identified and addressed by a unique name. |
static void |
setInfo(GameInfo info)
Sets the
Game's basic information by the specified GameInfo instance. |
static void |
setInfo(java.lang.String gameInfoFile)
Sets the
Game's basic information by loading the GameInfo from the specified path to an XML file. |
static void |
setInfo(java.net.URL gameInfoFile) |
static void |
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Sets an
UncaughtExceptionHandler used to handle all unexpected exceptions happening in the game. |
static void |
start()
Starts the
GameLoops and other components. |
static GameTime |
time()
Gets time information about the running game/environment.
|
static GameWindow |
window()
Gets the game's window in which the
RenderComponent lives.This class e.g. |
static GameWorld |
world()
Gets the game's world which is a global environment manager that contains all
Environments
and provides the currently active Environment and
Camera. |
public static final int EXIT_GAME_CLOSED
public static final int EXIT_GAME_CRASHED
public static final java.lang.String COMMADLINE_ARG_RELEASE
public static final java.lang.String COMMADLINE_ARG_NOGUI
public static void addGameListener(GameListener listener)
listener - The listener to add.public static void removeGameListener(GameListener listener)
listener - The listener to remove.public static void allowDebug(boolean allow)
COMMADLINE_ARG_RELEASE when running the game.allow - If set to true, the game will be told to allow debugging.public static void hideGUI(boolean noGui)
GameWindow or not.
This can only be set before the game has been initialized with the Game.init(String...) method. Afterwards it doesn't have an effect
anymore.
If enabled, the ScreenManager#setVisible(boolean) method won't be set to true and the RenderLoop won't be started.
Also the Camera won't be updated.noGui - If set to true, the GUI will be hidden.GameWindow,
init(String...),
Camera,
isInNoGUIMode()public static boolean isDebug()
allowDebug(boolean),
GameConfiguration.debug()public static boolean isInNoGUIMode()
GameWindow or not.public static boolean hasStarted()
start()public static GameInfo info()
Game.getInfo().setValue("CUSTOM_STRING", "my-value").GameInfo,
ICustomPropertyProvider,
GameInfo.setName(String),
CustomPropertyProvider.setValue(String, String)public static GameConfiguration config()
Elements of this configuration are also presented in a config.properties file in the game's root directory.
This way its possible to adjust elements without having to recompile the game.
SoundConfiguration,
GraphicConfiguration,
ClientConfiguration,
DebugConfiguration,
InputConfigurationpublic static GameMetrics metrics()
This information can be rendered by setting
Game.config().client().setShowGameMetrics(boolean) to true or
cl_showGameMetrics=true in the config.settings.
GameMetrics.getFramesPerSecond(),
ClientConfiguration.setShowGameMetrics(boolean)public static GameTime time()
This allow to measure the time between actions, track how long something took, evaluate cooldowns or just get information about the played game time.
GameTime.now()public static GameWindow window()
RenderComponent lives.RenderComponent.RenderComponent,
GameWindow.getResolution(),
GameWindow.setTitle(String),
GameWindow.setIcon(java.awt.Image),
GameWindow.cursor()public static SoundEngine audio()
SoundEngine component that can be used to play sounds and music.Resources API and are managed by theResources.sounds() resource container.
Upon playing a sound, the engine returns an SoundPlayback instance that can then be used to further control the audio line.
SoundEngine component.Sound,
Resources.sounds(),
SoundPlayback,
SoundEngine.playSound(de.gurkenlabs.litiengine.sound.Sound),
SoundEngine.playMusic(de.gurkenlabs.litiengine.sound.Sound)public static PhysicsEngine physics()
PhysicsEngine component that can be used to detect and resolve collision and move entities with respect to all
collision
entities on the environment.
It is also possible to manually register static collision Rectangles that can further restrict the game world.
PhysicsEngine component.PhysicsEngine,
PhysicsEngine.move(IMobileEntity, float),
ICollisionEntitypublic static RenderEngine graphics()
RenderEngine component that is used to render Images, Shapes or Text with respect to the environment
and the render scale and the Camera.
In case you want to render something in a static manner that is unrelated to the environment, you can use the engine's different static
Renderer implementations.
RenderEngine component.RenderEngine.getBaseRenderScale(),
TextRenderer,
ShapeRenderer,
ImageRendererpublic static IGameLoop loop()
Updatable instance to this loop if you want to execute custom game logic that is executed at the configured
max fps.
The game's loop also executes the rendering process on the GameFrame's RenderComponent.Graphics2D object to all GuiComponents and the
Environment for rendering.
The LITIengine has two separate loops for game logic/rendering and input processing.
This prevents them from interfering with each other and to be able to process player input independent of the game's framerate.
ClientConfiguration.getMaxFps(),
IUpdateable,
ILoop.attach(IUpdateable),
ILoop.detach(IUpdateable),
inputLoop()public static ILoop inputLoop()
We need an own update loop because otherwise input won't work if the game has been paused.
public static java.util.logging.Logger log()
public static ScreenManager screens()
ScreenManager that is responsible for organizing all Screens of your game and providing the currently
active Screen that is used to render the current Environment.Examples: Menu Screen, Credits Screen, Game Screen, Inventory Screen
Screen,
GameWorld.environment(),
world()public static GameWorld world()
Environments
and provides the currently active Environment and
Camera.
The GameWorld returns the same instance for a particular map/mapName until the
GameWorld.reset(String) method is called.
EnvironmentListeners to different events of the
Envrionment's life cycle (e.g. loaded, initialized, ...).GameWorld,
Environment,
Camera,
GameWorld.environment(),
GameWorld.camera(),
GameWorld.reset(String)public static void init(java.lang.String... args)
GameConfigurationLocale according to the configured values.PhysicsEngineScreenMangerInputGameLoop and RenderLoopCameraargs - The arguments passed to the programs entry point.public static void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
UncaughtExceptionHandler used to handle all unexpected exceptions happening in the game.uncaughtExceptionHandler - The handler to be used for uncaught exceptions.public static void start()
Starts the GameLoops and other components.
After this method is called, the engine will start to render contents of the current Screen of the ScreenManager,
the SoundEngine will start to playback Sounds
and the different input devices (e.g. Mouse, Keyboard) will start to process player input.
When the Game has started up successfully, it'll callback to the registered GameListeners.
public static void setInfo(GameInfo info)
Game's basic information by the specified GameInfo instance.
Typically, this should not be called manually because the Game already provides a GameInfo object which can be
adjusted.
If you just want to edit some of it's information, use the provided instance of info().
public static void setInfo(java.lang.String gameInfoFile)
Game's basic information by loading the GameInfo from the specified path to an XML file.gameInfoFile - The path to the XML file that contains the serialized GameInfo.setInfo(GameInfo),
info(),
GameInfopublic static void setInfo(java.net.URL gameInfoFile)