level

namespace level

a level manager. once ressources loaded, the level manager contains all references of defined levels.

Public Methods


add level.js:83
add(format: string, levelId: string, callback: Function) → {boolean}

add a level into the game manager (usually called by the preloader)

Parameters:
Name Type Attributes Description
format string

level format (only "tmx" supported)

levelId string

the level id (or name)

callback Function

<optional>

a function to be called once the level is loaded

Returns:
Type Description
boolean

true if the level was loaded

getCurrentLevel level.js:205
getCurrentLevel() → {TMXTileMap}

return the current level definition. for a reference to the live instantiated level, rather use the container in which it was loaded (e.g. me.game.world)

Returns:
Type Description
TMXTileMap
getCurrentLevelId level.js:194
getCurrentLevelId() → {string}

return the current level id

Returns:
Type Description
string
levelCount level.js:277
levelCount() → {number}

return the amount of level preloaded

Returns:
Type Description
number

the amount of level preloaded

load level.js:120
load(levelId: string, options: object) → {boolean}

load a level into the game manager
(will also create all level defined entities, etc..)

 // the game assets to be be preloaded
 // TMX maps
 let resources = [
     {name: "a4_level1",   type: "tmx",   src: "data/level/a4_level1.tmx"},
     {name: "a4_level2",   type: "tmx",   src: "data/level/a4_level2.tmx"},
     {name: "a4_level3",   type: "tmx",   src: "data/level/a4_level3.tmx"},
     // ...
 ];

 // ...

 // load a level into the game world
 me.level.load("a4_level1");
 ...
 ...
 // load a level into a specific container
 let levelContainer = new me.Container();
 me.level.load("a4_level2", {container:levelContainer});
 // add a simple transformation
 levelContainer.currentTransform.translate(levelContainer.width / 2, levelContainer.height / 2 );
 levelContainer.currentTransform.rotate(0.05);
 levelContainer.currentTransform.translate(-levelContainer.width / 2, -levelContainer.height / 2 );
 // add it to the game world
 me.game.world.addChild(levelContainer);
Parameters:
Name Type Attributes Default Description
levelId string

level id

options object

<optional>

additional optional parameters

options.container Container

<optional>

game.world

container in which to load the specified level

options.onLoaded Function

<optional>

game.onLevelLoaded

callback for when the level is fully loaded

options.flatten boolean

<optional>

game.mergeGroup

if true, flatten all objects into the given container

options.setViewportBounds boolean

<optional>

true

if true, set the viewport bounds to the map size

Returns:
Type Description
boolean

true if the level was successfully loaded

reload level.js:218
reload(options: object) → {object}

reload the current level

Parameters:
Name Type Attributes Default Description
options object

<optional>

additional optional parameters

options.container Container

<optional>

game.world

container in which to load the specified level

options.onLoaded Function

<optional>

game.onLevelLoaded

callback for when the level is fully loaded

options.flatten boolean

<optional>

game.mergeGroup

if true, flatten all objects into the given container

Returns:
Type Description
object

the current level


Powered by webdoc!