Source: animate/Scene.js

animate/Scene.js

  1. import load from './load';
  2. import sound from './sound';
  3. import * as core from '../core';
  4. /**
  5. * Extends the PIXI.Application class to provide easy loading.
  6. * ```
  7. * const scene = new PIXI.animate.Scene();
  8. * scene.load(lib.StageName);
  9. * ```
  10. * @class Scene
  11. * @memberof PIXI.animate
  12. * @param {Number} [width=800] Stage width
  13. * @param {Number} [height=600] Stage height
  14. * @param {Object} [renderOptions] See PIXI.Application for more info.
  15. * @param {Boolean} [noWebGL=false] Disable WebGL
  16. */
  17. class Scene extends core.Application {
  18. constructor(width, height, renderOptions, noWebGL) {
  19. super(width, height, renderOptions, noWebGL);
  20. /**
  21. * Reference to the global sound object
  22. * @name PIXI.animate.Scene#sound
  23. * @type {PIXI.animate.sound}
  24. * @readOnly
  25. */
  26. this.sound = sound;
  27. /**
  28. * The stage object created.
  29. * @name PIXI.animate.Scene#instance
  30. * @type {PIXI.animate.MovieClip}
  31. * @readOnly
  32. */
  33. this.instance = null;
  34. }
  35. /**
  36. * Load a stage scene and add it to the stage.
  37. * @method PIXI.animate.Scene#load
  38. * @param {Function} StageRef Reference to the stage class.
  39. * @param {Function} [complete] Callback when finished loading.
  40. * @param {String} [basePath] Optional base directory to prepend to assets.
  41. * @return {PIXI.loaders.Loader} instance of PIXI resource loader
  42. */
  43. load(StageRef, complete, basePath) {
  44. return load(StageRef, this.stage, (instance) => {
  45. this.instance = instance;
  46. if (complete) {
  47. complete(instance);
  48. }
  49. }, basePath);
  50. }
  51. /**
  52. * Destroy and don't use after calling.
  53. * @method PIXI.animate.Scene#destroy
  54. * @param {Boolean} [removeView=false] `true` to remove canvas element.
  55. */
  56. destroy(removeView) {
  57. if (this.instance) {
  58. this.instance.destroy(true);
  59. this.instance = null;
  60. }
  61. super.destroy(removeView);
  62. }
  63. }
  64. export default Scene;