level
namespace level
a level manager. once ressources loaded, the level manager contains all references of defined levels.
Summary
Methods from level
boolean |
|
TMXTileMap |
|
string |
|
number |
|
boolean |
|
boolean |
|
boolean |
|
object |
|
Public Methods
add(format: string, levelId: string, callback: Function) → {boolean}
add a level into the game manager (usually called by the preloader)
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 |
Type | Description |
---|---|
boolean |
true if the level was loaded |
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)
Type | Description |
---|---|
TMXTileMap |
getCurrentLevelId() → {string}
return the current level id
Type | Description |
---|---|
string |
levelCount() → {number}
return the amount of level preloaded
Type | Description |
---|---|
number |
the amount of level preloaded |
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);
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 |
Type | Description |
---|---|
boolean |
true if the level was successfully loaded |
next(options: object) → {boolean}
load the next level
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 |
Type | Description |
---|---|
boolean |
true if the next level was successfully loaded |
previous(options: object) → {boolean}
load the previous level
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 |
Type | Description |
---|---|
boolean |
true if the previous level was successfully loaded |
reload(options: object) → {object}
reload the current level
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 |
Type | Description |
---|---|
object |
the current level |