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 |
protected static long |
environmentLoadTick |
static int |
EXIT_GAME_CLOSED |
static int |
EXIT_GAME_CRASHED |
Modifier and Type | Method and Description |
---|---|
static void |
addEnvironmentLoadedListener(EnvironmentLoadedListener listener) |
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 ICamera |
getCamera() |
static GameConfiguration |
getConfiguration() |
static IEnvironment |
getEnvironment() |
static GameInfo |
getInfo() |
static IGameLoop |
getLoop() |
static IMap |
getMap(java.lang.String mapName)
Get a Map that was already loaded into memory by its name.
|
static java.util.List<IMap> |
getMaps()
Get a list of maps that are already loaded into memory.
|
static GameMetrics |
getMetrics() |
static IPhysicsEngine |
getPhysicsEngine() |
static RenderEngine |
getRenderEngine() |
static RenderLoop |
getRenderLoop() |
static IScreenManager |
getScreenManager() |
static ISoundEngine |
getSoundEngine() |
static java.util.List<ITileset> |
getTilesets() |
static GameTime |
getTime() |
static boolean |
hasStarted() |
static void |
hideGUI(boolean noGui)
This flag indicates whether the game should display the
ScreenManager or not. |
static void |
init(java.lang.String... args)
Initializes the infrastructure of the LITIengine game.
|
static boolean |
isDebug() |
static boolean |
isInNoGUIMode() |
static void |
load(java.lang.String gameResourceFile)
Load Spritesheets, Tilesets and Maps from a game resource file created with the utiLITI editor.
|
static void |
loadEnvironment(IEnvironment env) |
static void |
removeEnvironmentLoadedListener(EnvironmentLoadedListener listener) |
static void |
removeGameListener(GameListener listener) |
static void |
removeGameTerminatedListener(GameTerminatedListener listener) |
static void |
setCamera(ICamera cam) |
static void |
setInfo(GameInfo info) |
static void |
setInfo(java.lang.String gameInfoFile) |
static void |
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler) |
static void |
start()
Starts the
GameLoops and other components. |
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
protected static long environmentLoadTick
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 addEnvironmentLoadedListener(EnvironmentLoadedListener listener)
public static void removeEnvironmentLoadedListener(EnvironmentLoadedListener 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)
ScreenManager
or not.
This can only be set before the game has been initialized with the init(String...)
method. Afterwards it doesn't have an effect anymore.
If set to true, the Window.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.public static boolean isDebug()
public static boolean isInNoGUIMode()
public static GameConfiguration getConfiguration()
public static IEnvironment getEnvironment()
public static GameInfo getInfo()
public static IGameLoop getLoop()
public static IMap getMap(java.lang.String mapName)
mapName
- the name of the map you want to loadpublic static java.util.List<IMap> getMaps()
public static java.util.List<ITileset> getTilesets()
public static GameMetrics getMetrics()
public static IPhysicsEngine getPhysicsEngine()
public static RenderEngine getRenderEngine()
public static RenderLoop getRenderLoop()
public static IScreenManager getScreenManager()
public static ISoundEngine getSoundEngine()
public static ICamera getCamera()
public static GameTime getTime()
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 load(java.lang.String gameResourceFile)
gameResourceFile
- the file name of the game resource filepublic static void loadEnvironment(IEnvironment env)
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 setCamera(ICamera cam)
public static void setInfo(GameInfo info)
public static void setInfo(java.lang.String gameInfoFile)