* init the game instance (create a physic world, update starting time, etc..) * @param width - The width of the canvas viewport * @param height - The height of the canvas viewport * @param options - The optional parameters for the application and default renderer
( width: number, height: number, options?: Partial<ApplicationSettings>, )
| 280 | * @param options - The optional parameters for the application and default renderer |
| 281 | */ |
| 282 | init( |
| 283 | width: number, |
| 284 | height: number, |
| 285 | options?: Partial<ApplicationSettings>, |
| 286 | ): void { |
| 287 | // ensure the engine is bootstrapped |
| 288 | if (!initialized) { |
| 289 | boot(); |
| 290 | } |
| 291 | |
| 292 | const merged = { |
| 293 | ...defaultApplicationSettings, |
| 294 | ...(options || {}), |
| 295 | }; |
| 296 | |
| 297 | const autoScale = |
| 298 | merged.scale === "auto" || |
| 299 | /^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/.test( |
| 300 | merged.scaleMethod, |
| 301 | ); |
| 302 | |
| 303 | const settings = { |
| 304 | ...merged, |
| 305 | width, |
| 306 | height, |
| 307 | autoScale, |
| 308 | scale: autoScale ? 1.0 : +merged.scale || 1.0, |
| 309 | zoomX: 0, |
| 310 | zoomY: 0, |
| 311 | scaleMethod: /^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/.test( |
| 312 | merged.scaleMethod, |
| 313 | ) |
| 314 | ? merged.scaleMethod |
| 315 | : ScaleMethods.Fit, |
| 316 | } as ResolvedApplicationSettings; |
| 317 | |
| 318 | // override renderer settings if &webgl or &canvas is defined in the URL |
| 319 | const uriFragment = getUriFragment(); |
| 320 | if ( |
| 321 | uriFragment.webgl === true || |
| 322 | uriFragment.webgl1 === true || |
| 323 | uriFragment.webgl2 === true |
| 324 | ) { |
| 325 | settings.renderer = WEBGL; |
| 326 | if (uriFragment.webgl1 === true) { |
| 327 | settings.preferWebGL1 = true; |
| 328 | } |
| 329 | } else if (uriFragment.canvas === true) { |
| 330 | settings.renderer = CANVAS; |
| 331 | } |
| 332 | |
| 333 | // computed scaled size |
| 334 | settings.zoomX = width * settings.scale; |
| 335 | settings.zoomY = height * settings.scale; |
| 336 | |
| 337 | this.settings = settings; |
| 338 | |
| 339 | // identify parent element and/or the html target for resizing |
no test coverage detected