public final class GameWorld extends java.lang.Object implements IUpdateable
GameWorld
class is a global environment manager that contains all 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, ...).Environment
,
Camera
,
environment()
,
camera()
,
reset(String)
Constructor and Description |
---|
GameWorld()
You should never call this manually! Instead use the
Game.world() instance. |
Modifier and Type | Method and Description |
---|---|
void |
addListener(EnvironmentListener listener)
Adds the specified environment listener to receive events about the basic life-cycle of environments.
|
void |
addListener(java.lang.String mapName,
EnvironmentListener listener)
Adds the specified environment listener to receive events about the basic life-cycle of environments with the specified map name.
|
void |
addLoadedListener(EnvironmentLoadedListener listener)
Adds the specified environment loaded listener to receive events for when an environment gets loaded.
|
void |
addLoadedListener(java.lang.String mapName,
EnvironmentLoadedListener listener)
Adds the specified environment loaded listener to receive events for when an environment with the specified map name gets loaded.
|
void |
addUnloadedListener(EnvironmentUnloadedListener listener)
Adds the specified environment unloaded listener to receive events for when an environment gets unloaded.
|
void |
addUnloadedListener(java.lang.String mapName,
EnvironmentUnloadedListener listener)
Adds the specified environment unloaded listener to receive events for when an environment with the specified map name gets unloaded.
|
void |
attach(java.lang.String mapName,
IUpdateable updateable)
Attaches the specified updatable instance that only gets updated when an environment with the specified map name is currently loaded.
|
ICamera |
camera()
Gets the game's current
Camera . |
void |
clear()
Clears the currently active camera and environment, removes all previously loaded environments
and clears all listener lists.
|
boolean |
containsEnvironment(java.lang.String mapName)
Indicates whether this instance already contains an
Environment for the specified map name. |
void |
detach(java.lang.String mapName,
IUpdateable updateable)
Detaches the specified updatable instance from the updating of environments with the specified map name.
|
Environment |
environment()
Gets the game's current
Environment . |
Environment |
getEnvironment(IMap map)
Gets the environment that's related to the specified map.
This method implicitly creates a new Environment if necessary. |
Environment |
getEnvironment(java.lang.String mapName)
Gets the environment that's related to the specified mapName.
This method implicitly creates a new Environment if necessary. |
java.util.Collection<Environment> |
getEnvironments()
Gets all environments that are known to the game world.
|
int |
gravity()
Gets the game worlds gravity that is applied to any environment.
|
void |
loadEnvironment(Environment env)
Loads the specified
Environment and sets it as current environment of the game. |
Environment |
loadEnvironment(IMap map)
Loads the
Environment that is identified by the specified map and sets it as current environment of the game. |
Environment |
loadEnvironment(java.lang.String mapName)
Loads the
Environment that is identified by the specified map name and sets it as current environment of the game. |
void |
removeListener(EnvironmentListener listener)
Removes the specified environment listener.
|
void |
removeListener(java.lang.String mapName,
EnvironmentListener listener)
Removes the specified environment listener.
|
void |
removeLoadedListener(EnvironmentLoadedListener listener)
Removes the specified environment loaded listener.
|
void |
removeLoadedListener(java.lang.String mapName,
EnvironmentLoadedListener listener)
Removes the specified environment loaded listener for the specified map name.
|
void |
removeUnloadedListener(EnvironmentUnloadedListener listener)
Removes the specified environment unloaded listener.
|
void |
removeUnloadedListener(java.lang.String mapName,
EnvironmentUnloadedListener listener)
Removes the specified environment unloaded listener for the specified map name.
|
Environment |
reset(IMap map)
Resets the previously loaded
Environment for the specified map so that it can be re-initiated upon the next access. |
Environment |
reset(java.lang.String mapName)
Resets the previously loaded
Environment for the specified map name so that it can be re-initiated upon the next access. |
void |
setCamera(ICamera cam)
Sets the active camera of the game.
|
void |
setGravity(int gravity)
Specify the general gravity that will be used as default value for all environments that are loaded.
|
void |
unloadEnvironment()
Unloads the current
Environment and sets it to null. |
void |
update()
Don't call this manually!
|
public GameWorld()
You should never call this manually! Instead use the Game.world()
instance.
Game.world()
public void update()
update
in interface IUpdateable
ClientConfiguration.setMaxFps(int)
public void addListener(EnvironmentListener listener)
listener
- The listener to add.public void removeListener(EnvironmentListener listener)
listener
- The listener to remove.public void addLoadedListener(EnvironmentLoadedListener listener)
listener
- The listener to add.public void removeLoadedListener(EnvironmentLoadedListener listener)
listener
- The listener to remove.public void addUnloadedListener(EnvironmentUnloadedListener listener)
listener
- The listener to add.public void removeUnloadedListener(EnvironmentUnloadedListener listener)
listener
- The listener to remove.public void addLoadedListener(java.lang.String mapName, EnvironmentLoadedListener listener)
mapName
- The name of the map for which to add the listener.listener
- The listener to add.public void removeLoadedListener(java.lang.String mapName, EnvironmentLoadedListener listener)
mapName
- The name of the map for which to remove the listener.listener
- The listener to remove.public void addUnloadedListener(java.lang.String mapName, EnvironmentUnloadedListener listener)
mapName
- The name of the map for which to add the listener.listener
- The listener to add.public void removeUnloadedListener(java.lang.String mapName, EnvironmentUnloadedListener listener)
mapName
- The name of the map for which to remove the listener.listener
- The listener to remove.public void addListener(java.lang.String mapName, EnvironmentListener listener)
mapName
- The name of the map for which to add the listener.listener
- The listener to add.public void removeListener(java.lang.String mapName, EnvironmentListener listener)
mapName
- The name of the map for which to remove the listener.listener
- The listener to remove.public void attach(java.lang.String mapName, IUpdateable updateable)
mapName
- The name of the map for which to attach the updatable instance.updateable
- The updatable instance to attach.public void detach(java.lang.String mapName, IUpdateable updateable)
mapName
- The name of the map for which to detach the updatable instance.updateable
- The updatable instance to detach.public ICamera camera()
Camera
.ICamera
public Environment environment()
Environment
.Environment
public int gravity()
public void clear()
public java.util.Collection<Environment> getEnvironments()
public Environment getEnvironment(java.lang.String mapName)
Environment
if necessary.mapName
- The map name by which the environment is identified.public Environment getEnvironment(IMap map)
Environment
if necessary.map
- The map by which the environment is identified.public boolean containsEnvironment(java.lang.String mapName)
Environment
for the specified map name.mapName
- The map name by which the environment is identified.public void loadEnvironment(Environment env)
Environment
and sets it as current environment of the game.
This implicitly unloads the previously loaded environment (if present).
The loaded environment can then be accessed via GameWorld#environment()
.
env
- The environment to be loaded.environment()
public Environment loadEnvironment(java.lang.String mapName)
Environment
that is identified by the specified map name and sets it as current environment of the game.
This implicitly unloads the previously loaded environment (if present).
The loaded environment can then be accessed via GameWorld#environment()
.
mapName
- The map name by which the environment is identified.environment()
,
loadEnvironment(Environment)
public Environment loadEnvironment(IMap map)
Environment
that is identified by the specified map and sets it as current environment of the game.
This implicitly unloads the previously loaded environment (if present).
The loaded environment can then be accessed via GameWorld#environment()
.
map
- The map by which the environment is identified.environment()
,
loadEnvironment(Environment)
public void unloadEnvironment()
Environment
and sets it to null.public Environment reset(java.lang.String mapName)
Environment
for the specified map name so that it can be re-initiated upon the next access.
This can be used if one wants to completely reset the state of a level to its initial state. It'll just throw away the current environment instance and reload a new one upon the next access.
mapName
- The map name by which the environment is identified.getEnvironment(String)
,
reset(IMap)
public Environment reset(IMap map)
Environment
for the specified map so that it can be re-initiated upon the next access.
This can be used if one wants to completely reset the state of a level to its initial state. It'll just throw away the current environment instance and reload a new one upon the next access.
map
- The map by which the environment is identified.getEnvironment(String)
,
reset(IMap)
public void setCamera(ICamera cam)
cam
- The new camera to be set.public void setGravity(int gravity)
IMobileEntity
.gravity
- The default gravity for all environments.IMobileEntity.getVelocity()