egret_loader.js 3.3 KB

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