MCPcopy Create free account
hub / github.com/melonjs/melonJS / init

Method init

packages/melonjs/src/application/application.ts:282–597  ·  view source on GitHub ↗

* 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>,
	)

Source from the content-addressed store, hash-verified

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

Callers 1

constructorMethod · 0.95

Calls 10

bootFunction · 0.90
getUriFragmentFunction · 0.90
autoDetectRendererFunction · 0.90
emitFunction · 0.90
onFunction · 0.90
onresizeFunction · 0.90
consoleHeaderFunction · 0.90
setDefaultGameFunction · 0.85
resolvePhysicSettingFunction · 0.85
getCanvasMethod · 0.80

Tested by

no test coverage detected