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.
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) |
static void |
addGameTerminatedListener(GameTerminatedListener listener) |
static void |
allowDebug(boolean allow)
This flag indicates if the game currently supports debugging.
|
static ISoundEngine |
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() |
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 boolean |
isDebug()
This flag globally controls the game's debugging state.
|
static boolean |
isInNoGUIMode() |
static IGameLoop |
loop()
Gets the game's main loop that is used to execute and manage all game logic apart from rendering and 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
updaterate. |
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) |
static void |
removeGameTerminatedListener(GameTerminatedListener listener) |
static RenderLoop |
renderLoop()
Gets the game's loop that executes the rendering process on the GameFrame's
RenderComponent .This internally renders the currently active screen which passes the Graphics2D object to all GuiComponents and the
Environment for rendering. |
static IScreenManager |
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 |
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler) |
static void |
start()
Starts the
GameLoops and other components. |
static void |
terminate()
This method should not be called manually.
|
static GameTime |
time() |
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)
public static void removeGameListener(GameListener listener)
public static void addGameTerminatedListener(GameTerminatedListener listener)
public static void removeGameTerminatedListener(GameTerminatedListener listener)
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...)
,
Window.setVisible(boolean)
,
RenderLoop
,
Camera
public static boolean isDebug()
allowDebug(boolean)
,
GameConfiguration.debug()
public static boolean isInNoGUIMode()
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
,
InputConfiguration
public 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()
public static GameWindow window()
RenderComponent
lives.RenderComponent
.RenderComponent
,
GameWindow.getResolution()
,
GameWindow.setTitle(String)
,
GameWindow.setIconImage(java.awt.Image)
public static ISoundEngine 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 ISoundPlayback
instance that can then be used to further control the audio line.
SoundEngine
component.Sound
,
Resources.sounds()
,
ISoundPlayback
,
ISoundEngine.playSound(de.gurkenlabs.litiengine.sound.Sound)
,
ISoundEngine.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)
,
ICollisionEntity
public 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
,
ImageRenderer
public static IGameLoop loop()
Updatable
instance to this loop if you want to execute custom game logic that is executed at the configured
updaterate.
The LITIengine has separate loops for game logic, rendering and input processing.
This prevents them from interfering with each other and also properly separates tasks by their category.
ClientConfiguration.getUpdaterate()
,
IUpdateable
,
ILoop.attach(IUpdateable)
,
ILoop.detach(IUpdateable)
,
Input.getLoop()
,
renderLoop()
public static RenderLoop renderLoop()
RenderComponent
.Graphics2D
object to all GuiComponents
and the
Environment for rendering. This loop will try to execute at the configured frames-per-second and limit the frames to this value.
It's also possible to register Updatable
instances to this loop which is useful if you want to execute something that is directly
related to
the rendering process and needs to be executed right before the game's rendering starts.
ClientConfiguration.getMaxFps()
,
RenderComponent.render()
,
GuiComponent.render(java.awt.Graphics2D)
,
GuiComponent.render(java.awt.Graphics2D)
,
Environment.render(java.awt.Graphics2D)
public static IScreenManager 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()
public static boolean hasStarted()
public static void init(java.lang.String... args)
GameConfiguration
Locale
according to the configured values.PhysicsEngine
ScreenManger
Input
GameLoop
and RenderLoop
args
- The arguments passed to the programs entry point.public static void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
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
.
ScreenManager.current()
,
SoundEngine
,
Input
,
GameListener.started()
public static void terminate()
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()
,
GameInfo