* load a level into the game manager * (will also create all level defined entities, etc..) * @name load * @memberof level * @public * @param {string} levelId - level id * @param {object} [options] - additional optional parameters * @param {Container} [options.container=game.world]
(levelId, options)
| 176 | * app.world.addChild(levelContainer); |
| 177 | */ |
| 178 | load(levelId, options) { |
| 179 | options = Object.assign( |
| 180 | { |
| 181 | container: game.world, |
| 182 | onLoaded: game.onLevelLoaded, |
| 183 | flatten: game.mergeGroup, |
| 184 | setViewportBounds: true, |
| 185 | }, |
| 186 | options || {}, |
| 187 | ); |
| 188 | |
| 189 | // throw an exception if not existing |
| 190 | if (typeof levels[levelId] === "undefined") { |
| 191 | throw new Error("level " + levelId + " not found"); |
| 192 | } |
| 193 | |
| 194 | // check the status of the state mngr |
| 195 | const wasRunning = state.isRunning(); |
| 196 | |
| 197 | if (wasRunning) { |
| 198 | // stop the game loop to avoid |
| 199 | // some silly side effects |
| 200 | state.stop(); |
| 201 | |
| 202 | setTimeout(() => { |
| 203 | safeLoadLevel(levelId, options, true); |
| 204 | }); |
| 205 | } else { |
| 206 | safeLoadLevel(levelId, options); |
| 207 | } |
| 208 | return true; |
| 209 | }, |
| 210 | |
| 211 | /** |
| 212 | * return the current level id<br> |
nothing calls this directly
no test coverage detected