Skip to content

Commit

Permalink
[chore] Remove deprecated PauseAfterLoader (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeen authored and eonarheim committed Dec 23, 2018
1 parent bd8ad14 commit 5e81eee
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 257 deletions.
37 changes: 0 additions & 37 deletions sandbox/tests/loader/pauseafter/index.html

This file was deleted.

37 changes: 0 additions & 37 deletions sandbox/tests/loader/pauseafter/ios.html

This file was deleted.

33 changes: 0 additions & 33 deletions sandbox/tests/loader/pauseafter/ios.ts

This file was deleted.

21 changes: 0 additions & 21 deletions sandbox/tests/loader/pauseafter/pauseafter.ts

This file was deleted.

129 changes: 0 additions & 129 deletions src/engine/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ILoadable } from './Interfaces/ILoadable';
import { ILoader } from './Interfaces/ILoader';
import { Class } from './Class';
import * as DrawUtil from './Util/DrawUtil';
import { obsolete } from './Util/Decorators';

import logoImg from './Loader.logo.png';
import loaderCss from './Loader.css';
Expand Down Expand Up @@ -371,131 +370,3 @@ export class Loader extends Class implements ILoader {
return;
};
}

/**
* @obsolete Use [[Loader]] instead, this functionality has been made default
*
* A [[Loader]] that pauses after loading to allow user
* to proceed to play the game. Typically you will
* want to use this loader for iOS to allow sounds
* to play after loading (Apple Safari requires user
* interaction to allow sounds, even for games)
*
* **Note:** Because Loader is not part of a Scene, you must
* call `update` and `draw` manually on "child" objects.
*
* ## Implementing a Trigger
*
* The `PauseAfterLoader` requires an element to act as the trigger button
* to start the game.
*
* For example, let's create an `<a>` tag to be our trigger and call it `tap-to-play`.
*
* ```html
* <div id="wrapper">
* <canvas id="game"></canvas>
* <a id="tap-to-play" href='javascript:void(0);'>Tap to Play</a>
* </div>
* ```
*
* We've put it inside a wrapper to position it properly over the game canvas.
*
* Now let's add some CSS to style it (insert into `<head>`):
*
* ```html
* <style>
* #wrapper {
* position: relative;
* width: 500px;
* height: 500px;
* }
* #tap-to-play {
* display: none;
* font-size: 24px;
* font-family: sans-serif;
* text-align: center;
* border: 3px solid white;
* position: absolute;
* color: white;
* width: 200px;
* height: 50px;
* line-height: 50px;
* text-decoration: none;
* left: 147px;
* top: 80%;
* }
* </style>
* ```
*
* Now we can create a `PauseAfterLoader` with a reference to our trigger button:
*
* ```ts
* var loader = new ex.PauseAfterLoader('tap-to-play', [...]);
* ```
*
* ## Use PauseAfterLoader for iOS
*
* The primary use case for pausing before starting the game is to
* pass Apple's requirement of user interaction. The Web Audio context
* in Safari is disabled by default until user interaction.
*
* Therefore, you can use this snippet to only use PauseAfterLoader when
* iOS is detected (see [this thread](http://stackoverflow.com/questions/9038625/detect-if-device-is-ios)
* for more techniques).
*
* ```ts
* var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(<any>window).MSStream;
* var loader: ex.Loader = iOS ? new ex.PauseAfterLoader('tap-to-play') : new ex.Loader();
*
* loader.addResource(...);
* ```
*/
export class PauseAfterLoader extends Loader {
private _loadedValue: any;
private _waitPromise: Promise<any>;
private _playTrigger: HTMLElement;

constructor(triggerElementId: string, loadables?: ILoadable[]) {
super(loadables);

this._playTrigger = document.getElementById(triggerElementId);
this._playTrigger.addEventListener('click', this._handleOnTrigger);
}

@obsolete({ message: 'Deprecated in v0.20.0', alternateMethod: 'Use ex.Loader instead' })
public load(): Promise<any> {
this._waitPromise = new Promise<any>();

// wait until user indicates to proceed before finishing load
super.load().then(
(value?) => {
this._loadedValue = value;

// show element
this._playTrigger.style.display = 'block';
},
(value?) => {
this._waitPromise.reject(value);
}
);

return this._waitPromise;
}

private _handleOnTrigger = () => {
if (this._waitPromise.state() !== PromiseState.Pending) {
return false;
}

// unlock Safari WebAudio context
WebAudio.unlock();

// continue to play game
this._waitPromise.resolve(this._loadedValue);

// hide DOM element
this._playTrigger.style.display = 'none';

return false;
};
}

0 comments on commit 5e81eee

Please sign in to comment.