Class GameWorld
- All Implemented Interfaces:
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, ...).This is typically used to provide some per-level logic or to trigger general loading behavior.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionYou should never call this manually! Instead use theGame.world()instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(EnvironmentListener listener) Adds the specified environment listener to receive events about the basic life-cycle of environments.voidaddListener(String mapName, EnvironmentListener listener) Adds the specified environment listener to receive events about the basic life-cycle of environments with the specified map name.voidattach(String mapName, IUpdateable updateable) Attaches the specified updatable instance that only gets updated when an environment with the specified map name is currently loaded.camera()Gets the game's currentCamera.voidclear()Clears the currently active camera and environment, removes all previously loaded environments and clears all listener lists.booleancontainsEnvironment(String mapName) Indicates whether this instance already contains anEnvironmentfor the specified map name.voiddetach(String mapName, IUpdateable updateable) Detaches the specified updatable instance from the updating of environments with the specified map name.Gets the game's currentEnvironment.getEnvironment(IMap map) Gets the environment that's related to the specified map.
This method implicitly creates a newEnvironmentif necessary.getEnvironment(String mapName) Gets the environment that's related to the specified mapName.
This method implicitly creates a newEnvironmentif necessary.Gets all environments that are known to the game world.intgravity()Gets the game worlds gravity that is applied to any environment.voidLoads the specifiedEnvironmentand sets it as current environment of the game.loadEnvironment(IMap map) Loads theEnvironmentthat is identified by the specified map and sets it as current environment of the game.loadEnvironment(String mapName) Loads theEnvironmentthat is identified by the specified map name and sets it as current environment of the game.voidonLoaded(EnvironmentLoadedListener listener) Adds the specified environment loaded listener to receive events for when an environment gets loaded.voidonLoaded(String mapName, EnvironmentLoadedListener listener) Adds the specified environment loaded listener to receive events for when an environment with the specified map name gets loaded.voidonUnloaded(EnvironmentUnloadedListener listener) Adds the specified environment unloaded listener to receive events for when an environment gets unloaded.voidonUnloaded(String mapName, EnvironmentUnloadedListener listener) Adds the specified environment unloaded listener to receive events for when an environment with the specified map name gets unloaded.voidremoveListener(EnvironmentListener listener) Removes the specified environment listener.voidremoveListener(String mapName, EnvironmentListener listener) Removes the specified environment listener.voidRemoves the specified environment loaded listener.voidremoveLoadedListener(String mapName, EnvironmentLoadedListener listener) Removes the specified environment loaded listener for the specified map name.voidRemoves the specified environment unloaded listener.voidremoveUnloadedListener(String mapName, EnvironmentUnloadedListener listener) Removes the specified environment unloaded listener for the specified map name.Resets the previously loadedEnvironmentfor the specified map so that it can be re-initiated upon the next access.Resets the previously loadedEnvironmentfor the specified map name so that it can be re-initiated upon the next access.voidSets the active camera of the game.voidsetGravity(int gravity) Specify the general gravity that will be used as default value for all environments that are loaded.voidUnloads the currentEnvironmentand sets it to null.voidupdate()Don't call this manually!
-
Constructor Details
-
GameWorld
public GameWorld()You should never call this manually! Instead use the
Game.world()instance.- See Also:
-
-
Method Details
-
update
public void update()Don't call this manually!- Specified by:
updatein interfaceIUpdateable- See Also:
-
addListener
Adds the specified environment listener to receive events about the basic life-cycle of environments. This is a global event that gets called for any map.- Parameters:
listener- The listener to add.
-
removeListener
Removes the specified environment listener.- Parameters:
listener- The listener to remove.
-
onLoaded
Adds the specified environment loaded listener to receive events for when an environment gets loaded. This is a global event that gets called for any map.- Parameters:
listener- The listener to add.
-
removeLoadedListener
Removes the specified environment loaded listener.- Parameters:
listener- The listener to remove.
-
onUnloaded
Adds the specified environment unloaded listener to receive events for when an environment gets unloaded. This is a global event that gets called for any map.- Parameters:
listener- The listener to add.
-
removeUnloadedListener
Removes the specified environment unloaded listener.- Parameters:
listener- The listener to remove.
-
onLoaded
Adds the specified environment loaded listener to receive events for when an environment with the specified map name gets loaded.- Parameters:
mapName- The name of the map for which to add the listener.listener- The listener to add.
-
removeLoadedListener
Removes the specified environment loaded listener for the specified map name.- Parameters:
mapName- The name of the map for which to remove the listener.listener- The listener to remove.
-
onUnloaded
Adds the specified environment unloaded listener to receive events for when an environment with the specified map name gets unloaded.- Parameters:
mapName- The name of the map for which to add the listener.listener- The listener to add.
-
removeUnloadedListener
Removes the specified environment unloaded listener for the specified map name.- Parameters:
mapName- The name of the map for which to remove the listener.listener- The listener to remove.
-
addListener
Adds the specified environment listener to receive events about the basic life-cycle of environments with the specified map name.- Parameters:
mapName- The name of the map for which to add the listener.listener- The listener to add.
-
removeListener
Removes the specified environment listener.- Parameters:
mapName- The name of the map for which to remove the listener.listener- The listener to remove.
-
attach
Attaches the specified updatable instance that only gets updated when an environment with the specified map name is currently loaded.- Parameters:
mapName- The name of the map for which to attach the updatable instance.updateable- The updatable instance to attach.
-
detach
Detaches the specified updatable instance from the updating of environments with the specified map name.- Parameters:
mapName- The name of the map for which to detach the updatable instance.updateable- The updatable instance to detach.
-
camera
Gets the game's currentCamera.- Returns:
- The currently active camera.
- See Also:
-
environment
Gets the game's currentEnvironment.- Returns:
- The currently active environment.
- See Also:
-
gravity
public int gravity()Gets the game worlds gravity that is applied to any environment. This can e.g. be useful for platformers.- Returns:
- The gravity of the game world that gets applied to any environment.
-
clear
public void clear()Clears the currently active camera and environment, removes all previously loaded environments and clears all listener lists. -
getEnvironments
Gets all environments that are known to the game world.- Returns:
- All known environments.
-
getEnvironment
Gets the environment that's related to the specified mapName.
This method implicitly creates a newEnvironmentif necessary.- Parameters:
mapName- The map name by which the environment is identified.- Returns:
- The environment for the map name or null if no such map can be found.
-
getEnvironment
Gets the environment that's related to the specified map.
This method implicitly creates a newEnvironmentif necessary.- Parameters:
map- The map by which the environment is identified.- Returns:
- The environment for the map or null if no such map can be found.
-
containsEnvironment
Indicates whether this instance already contains anEnvironmentfor the specified map name.- Parameters:
mapName- The map name by which the environment is identified.- Returns:
- True if the game world already has an environment for the specified map name; otherwise false.
-
loadEnvironment
Loads the specifiedEnvironmentand 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().- Parameters:
env- The environment to be loaded.- See Also:
-
loadEnvironment
Loads theEnvironmentthat 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().- Parameters:
mapName- The map name by which the environment is identified.- Returns:
- The loaded environment.
- See Also:
-
loadEnvironment
Loads theEnvironmentthat 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().- Parameters:
map- The map by which the environment is identified.- Returns:
- The loaded environment.
- See Also:
-
unloadEnvironment
public void unloadEnvironment()Unloads the currentEnvironmentand sets it to null. -
reset
Resets the previously loadedEnvironmentfor 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.
- Parameters:
mapName- The map name by which the environment is identified.- Returns:
- The environment instance that was reset or null if none was previously loaded.
- See Also:
-
reset
Resets the previously loadedEnvironmentfor 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.
- Parameters:
map- The map by which the environment is identified.- Returns:
- The environment instance that was reset or null if none was previously loaded.
- See Also:
-
setCamera
Sets the active camera of the game.- Parameters:
cam- The new camera to be set.
-
setGravity
public void setGravity(int gravity) Specify the general gravity that will be used as default value for all environments that are loaded. The value's unit of measure is pixel/second (similar to the velocity of aIMobileEntity.- Parameters:
gravity- The default gravity for all environments.- See Also:
-