egret_loader.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2014-2015, Egret Technology Inc.
  4. // All rights reserved.
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright
  11. // notice, this list of conditions and the following disclaimer in the
  12. // documentation and/or other materials provided with the distribution.
  13. // * Neither the name of the Egret nor the
  14. // names of its contributors may be used to endorse or promote products
  15. // derived from this software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  18. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  23. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  25. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  26. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. //
  28. //////////////////////////////////////////////////////////////////////////////////////
  29. egret_h5.startGame = function () {
  30. var context = egret.MainContext.instance;
  31. context.touchContext = new egret.HTML5TouchContext();
  32. context.deviceContext = new egret.HTML5DeviceContext();
  33. context.netContext = new egret.HTML5NetContext();
  34. egret.StageDelegate.getInstance().setDesignSize(480, 800);
  35. context.stage = new egret.Stage();
  36. //var scaleMode = egret.MainContext.deviceType == egret.MainContext.DEVICE_MOBILE ? egret.StageScaleMode.SHOW_ALL : egret.StageScaleMode.NO_SCALE;
  37. context.stage.scaleMode = egret.StageScaleMode.SHOW_ALL;
  38. //WebGL is a Egret's beta property. It's off by default.
  39. //WebGL是egret的Beta特性,默认关闭
  40. var rendererType = 0;
  41. if (rendererType == 1) {// egret.WebGLUtils.checkCanUseWebGL()) {
  42. console.log("Use WebGL mode");
  43. context.rendererContext = new egret.WebGLRenderer();
  44. }
  45. else {
  46. context.rendererContext = new egret.HTML5CanvasRenderer();
  47. }
  48. egret.MainContext.instance.rendererContext.texture_scale_factor = 1;
  49. context.run();
  50. var rootClass;
  51. if (document_class) {
  52. rootClass = egret.getDefinitionByName(document_class);
  53. }
  54. if (rootClass) {
  55. var rootContainer = new rootClass();
  56. if (rootContainer instanceof egret.DisplayObjectContainer) {
  57. context.stage.addChild(rootContainer);
  58. }
  59. else {
  60. throw new Error("Document Class must be the subclass to egret.DisplayObjectContainer!");
  61. }
  62. }
  63. else {
  64. throw new Error("Document Class is not found!");
  65. }
  66. //处理屏幕大小改变
  67. //implement for screen size change
  68. var resizeTimer = null;
  69. var doResize = function () {
  70. context.stage.changeSize();
  71. resizeTimer = null;
  72. };
  73. window.onresize = function () {
  74. if (resizeTimer == null) {
  75. resizeTimer = setTimeout(doResize, 300);
  76. }
  77. };
  78. };