diff --git a/CHANGELOG.md b/CHANGELOG.md
index f9beb597f..1e22a8b33 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -62,6 +62,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
+- Added fullscreen after load feature! You can optionally provide a `fullscreenContainer` with a string id or an instance of the `HTMLElement`
+ ```typescript
+ new ex.Loader({
+ fullscreenAfterLoad: true,
+ fullscreenContainer: document.getElementById('container')
+ });
+ ```
- Added new `ex.Debug` static for more convenient debug drawing where you might not have a graphics context accessible to you. This works by batching up all the debug draw requests and flushing them during the debug draw step.
* `ex.Debug.drawRay(ray: Ray, options?: { distance?: number, color?: Color })`
* `ex.Debug.drawBounds(boundingBox: BoundingBox, options?: { color?: Color })`
diff --git a/sandbox/html/index.html b/sandbox/html/index.html
index fdede2376..7eebaa68c 100644
--- a/sandbox/html/index.html
+++ b/sandbox/html/index.html
@@ -37,6 +37,7 @@
+
stuff
diff --git a/sandbox/src/game.ts b/sandbox/src/game.ts
index 74e02a454..f6da1a268 100644
--- a/sandbox/src/game.ts
+++ b/sandbox/src/game.ts
@@ -153,7 +153,10 @@ cards2.draw(game.graphicsContext, 0, 0);
jump.volume = 0.3;
-var boot = new ex.Loader();
+var boot = new ex.Loader({
+ fullscreenAfterLoad: true,
+ fullscreenContainer: document.getElementById('container')
+});
boot.addResource(heartImageSource);
boot.addResource(heartTex);
boot.addResource(imageRun);
diff --git a/src/engine/Director/DefaultLoader.ts b/src/engine/Director/DefaultLoader.ts
index bafe3dcc8..c04a79e7d 100644
--- a/src/engine/Director/DefaultLoader.ts
+++ b/src/engine/Director/DefaultLoader.ts
@@ -10,8 +10,11 @@ import { EventEmitter, EventKey, Handler, Subscription } from '../EventEmitter';
import { Color } from '../Color';
import { delay } from '../Util/Util';
-export interface LoaderOptions {
- loadables: Loadable[];
+export interface DefaultLoaderOptions {
+ /**
+ * List of loadables
+ */
+ loadables?: Loadable[];
}
export type LoaderEvents = {
@@ -60,7 +63,7 @@ export class DefaultLoader implements Loadable[]> {
/**
* @param options Optionally provide the list of resources you want to load at constructor time
*/
- constructor(options?: LoaderOptions) {
+ constructor(options?: DefaultLoaderOptions) {
if (options && options.loadables?.length) {
this.addResources(options.loadables);
}
diff --git a/src/engine/Director/Loader.ts b/src/engine/Director/Loader.ts
index 5d1b183fc..0fc09a5b9 100644
--- a/src/engine/Director/Loader.ts
+++ b/src/engine/Director/Loader.ts
@@ -7,9 +7,21 @@ import loaderCss from './Loader.css';
import { Vector } from '../Math/vector';
import { delay } from '../Util/Util';
import { EventEmitter } from '../EventEmitter';
-import { DefaultLoader } from './DefaultLoader';
+import { DefaultLoader, DefaultLoaderOptions } from './DefaultLoader';
import { Engine } from '../Engine';
import { Screen } from '../Screen';
+import { Logger } from '../Util/Log';
+
+export interface LoaderOptions extends DefaultLoaderOptions {
+ /**
+ * Go fullscreen after loading and clicking play
+ */
+ fullscreenAfterLoad?: boolean;
+ /**
+ * Fullscreen container element or id
+ */
+ fullscreenContainer?: HTMLElement | string;
+}
/**
* Pre-loading assets
@@ -77,6 +89,13 @@ import { Screen } from '../Screen';
* ```
*/
export class Loader extends DefaultLoader {
+ private _logger = Logger.getInstance();
+ private static _DEFAULT_LOADER_OPTIONS: LoaderOptions = {
+ loadables: [],
+ fullscreenAfterLoad: false,
+ fullscreenContainer: undefined
+ };
+ private _originalOptions: LoaderOptions = {loadables:[]};
public events = new EventEmitter();
public screen: Screen;
private _playButtonShown: boolean = false;
@@ -178,11 +197,20 @@ export class Loader extends DefaultLoader {
return buttonElement;
};
+ /**
+ * @param options Optionally provide options to loader
+ */
+ constructor(options?: LoaderOptions);
/**
* @param loadables Optionally provide the list of resources you want to load at constructor time
*/
- constructor(loadables?: Loadable[]) {
- super({loadables});
+ constructor(loadables?: Loadable[]);
+ constructor(loadablesOrOptions?: Loadable[] | LoaderOptions) {
+ const options = Array.isArray(loadablesOrOptions) ? {
+ loadables: loadablesOrOptions
+ } : loadablesOrOptions;
+ super(options);
+ this._originalOptions = { ...Loader._DEFAULT_LOADER_OPTIONS, ...options };
}
public override onInitialize(engine: Engine): void {
@@ -219,8 +247,8 @@ export class Loader extends DefaultLoader {
}
});
this._positionPlayButton();
- const playButtonClicked = new Promise((resolve) => {
- const startButtonHandler = (e: Event) => {
+ const playButtonClicked = new Promise(resolve => {
+ const startButtonHandler = (e: Event) => {
// We want to stop propagation to keep bubbling to the engine pointer handlers
e.stopPropagation();
// Hide Button after click
@@ -228,6 +256,20 @@ export class Loader extends DefaultLoader {
if (this.engine?.browser) {
this.engine.browser.window.off('resize', resizeHandler);
}
+
+ if (this._originalOptions.fullscreenAfterLoad) {
+ try {
+ this._logger.info('requesting fullscreen');
+ if (this._originalOptions.fullscreenContainer instanceof HTMLElement) {
+ this._originalOptions.fullscreenContainer.requestFullscreen();
+ } else {
+ this.engine.screen.goFullScreen(this._originalOptions.fullscreenContainer);
+ }
+ } catch (error) {
+ this._logger.error('could not go fullscreen', error);
+ }
+ }
+
resolve();
};
this._playButton.addEventListener('click', startButtonHandler);