Egret社区
手机屏幕切换到横屏时,游戏界面居然大于屏幕的像素宽高。
使用egret引擎开发游戏,游戏的宽高是800*600 。我把手机切换到横屏时,刷新浏览器,游戏的界面宽高居然会大于大于iphone5c的像素大小,iphone5c的分辨率是:1136x640像素
分享到 :
0 人收藏

8 个回复

倒序浏览
webflasher  初学乍练 | 2014-8-15 11:00:51
哪位大神能给出解答
guoshaorui  超级斑竹 | 2014-8-15 11:19:48
这个取决于你的屏幕适配代码是怎么写的
webflasher  初学乍练 | 2014-8-15 11:22:05
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>HelloWorld</title>
  6.     <meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
  7.     <meta name="apple-mobile-web-app-capable" content="yes"/>

  8.     <meta name="full-screen" content="true"/>
  9.     <meta name="screen-orientation" content="landscape"/>
  10.     <meta name="x5-fullscreen" content="true"/>
  11.     <meta name="360-fullscreen" content="true"/>
  12.     <base href="../"/>

  13.     <style>
  14.         body
  15.         {
  16.             text-align: center;
  17.             background: #FFFFFF;
  18.             padding: 0;
  19.             border: 0;
  20.             margin: 0;
  21.             height: 100%;
  22.         }
  23.         html
  24.         {
  25.             -ms-touch-action: none; /* Direct all pointer events to JavaScript code. */
  26.         }
  27.     </style>
  28. </head>
  29. <body>
  30. <div style="display:inline-block;width:100%; height:100%;margin: 0 auto; background: white; position:relative;" id="gameDiv">
  31.     <canvas id="gameCanvas" width="800" height="600" style="background-color: #000000"></canvas>
  32. </div>
  33. <script>var document_class = "GameApp";</script><!--这部分内容在编译时会被替换,要修改文档类,请到工程目录下的egretProperties.json内编辑。-->
  34. <script src="bin-debug/lib/egret_file_list.js"></script>
  35. <script src="launcher/egret_loader.js"></script>
  36. <script src="bin-debug/src/game_file_list.js"></script>

  37. <script>
  38.     egret_h5.preloadScript(egret_file_list, "bin-debug/lib/");
  39.     egret_h5.preloadScript(game_file_list, "bin-debug/src/");
  40.     egret_h5.startLoading();
  41. </script>
  42. </body>
  43. </html>
复制代码
webflasher  初学乍练 | 2014-8-15 11:26:49
guoshaorui 发表于 2014-8-15 11:19
这个取决于你的屏幕适配代码是怎么写的

super斑竹, 我把系统的适配方案贴了上来。麻烦你给看一下是什么原因,3Q
guoshaorui  超级斑竹 | 2014-8-15 11:29:56
webflasher 发表于 2014-8-15 11:26
super斑竹, 我把系统的适配方案贴了上来。麻烦你给看一下是什么原因,3Q

贴egret_loader.js的代码
webflasher  初学乍练 | 2014-8-15 11:33:27
  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 = {};

  28. egret_h5.prefix = "";

  29. egret_h5.loadScript = function (list, callback) {
  30.     var loaded = 0;
  31.     var loadNext = function () {
  32.         egret_h5.loadSingleScript(egret_h5.prefix + list[loaded], function () {
  33.             loaded++;
  34.             if (loaded >= list.length) {
  35.                 callback();
  36.             }
  37.             else {
  38.                 loadNext();
  39.             }
  40.         })
  41.     };
  42.     loadNext();
  43. }

  44. egret_h5.loadSingleScript = function (src, callback) {
  45.     var s = document.createElement('script');
  46.     if (s.hasOwnProperty("async")) {
  47.         s.async = false;
  48.     }
  49.     s.src = src;
  50.     s.addEventListener('load', function () {
  51.         this.removeEventListener('load', arguments.callee, false);
  52.         callback();
  53.     }, false);
  54.     document.body.appendChild(s);
  55. }

  56. egret_h5.startGame = function () {
  57.     var canvas = document.getElementById(egret.StageDelegate.canvas_name);
  58.     context = egret.MainContext.instance;
  59.     context.touchContext = new egret.HTML5TouchContext(canvas);
  60.     context.deviceContext = new egret.HTML5DeviceContext();
  61.     context.netContext = new egret.HTML5NetContext();


  62.     //设置屏幕适配策略
  63.     var container = new egret.EqualToFrame();
  64.     var content = egret.Browser.getInstance().isMobile ? new egret.FixedWidth() : new egret.NoScale();
  65.     var policy = new egret.ResolutionPolicy(container, content);
  66.     egret.StageDelegate.getInstance().setDesignSize(480, 800, policy);

  67.     context.stage = new egret.Stage(canvas.width, canvas.height);

  68.     //WebGL是egret的Beta特性,默认关闭
  69.     if(false){// egret.WebGLUtils.checkCanUseWebGL()) {
  70.         context.rendererContext = new egret.WebGLRenderer(canvas);
  71.     }
  72.     else {
  73.         context.rendererContext = new egret.HTML5CanvasRenderer(canvas);
  74.     }

  75.     egret.MainContext.instance.rendererContext.texture_scale_factor = 1;
  76.     context.run();

  77.     var rootClass;
  78.     if(document_class){
  79.         rootClass = egret.getDefinitionByName(document_class);
  80.     }
  81.     if(rootClass) {
  82.         var rootContainer = new rootClass();
  83.         if(rootContainer instanceof egret.DisplayObjectContainer){
  84.             context.stage.addChild(rootContainer);
  85.         }
  86.         else{
  87.             throw new Error("文档类必须是egret.DisplayObjectContainer的子类!");
  88.         }
  89.     }
  90.     else{
  91.         throw new Error("找不到文档类!");
  92.     }
  93. }

  94. egret_h5.preloadScript = function (list, prefix) {
  95.     if (!egret_h5.preloadList) {
  96.         egret_h5.preloadList = [];
  97.     }
  98.     egret_h5.preloadList = egret_h5.preloadList.concat(list.map(function (item) {
  99.         return prefix + item;
  100.     }))
  101. }

  102. egret_h5.startLoading = function () {
  103.     var list = egret_h5.preloadList;
  104.     egret_h5.loadScript(list, egret_h5.startGame);
  105. }
复制代码
webflasher  初学乍练 | 2014-8-15 11:33:47
  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 = {};

  28. egret_h5.prefix = "";

  29. egret_h5.loadScript = function (list, callback) {
  30.     var loaded = 0;
  31.     var loadNext = function () {
  32.         egret_h5.loadSingleScript(egret_h5.prefix + list[loaded], function () {
  33.             loaded++;
  34.             if (loaded >= list.length) {
  35.                 callback();
  36.             }
  37.             else {
  38.                 loadNext();
  39.             }
  40.         })
  41.     };
  42.     loadNext();
  43. }

  44. egret_h5.loadSingleScript = function (src, callback) {
  45.     var s = document.createElement('script');
  46.     if (s.hasOwnProperty("async")) {
  47.         s.async = false;
  48.     }
  49.     s.src = src;
  50.     s.addEventListener('load', function () {
  51.         this.removeEventListener('load', arguments.callee, false);
  52.         callback();
  53.     }, false);
  54.     document.body.appendChild(s);
  55. }

  56. egret_h5.startGame = function () {
  57.     var canvas = document.getElementById(egret.StageDelegate.canvas_name);
  58.     context = egret.MainContext.instance;
  59.     context.touchContext = new egret.HTML5TouchContext(canvas);
  60.     context.deviceContext = new egret.HTML5DeviceContext();
  61.     context.netContext = new egret.HTML5NetContext();


  62.     //设置屏幕适配策略
  63.     var container = new egret.EqualToFrame();
  64.     var content = egret.Browser.getInstance().isMobile ? new egret.FixedWidth() : new egret.NoScale();
  65.     var policy = new egret.ResolutionPolicy(container, content);
  66.     egret.StageDelegate.getInstance().setDesignSize(480, 800, policy);

  67.     context.stage = new egret.Stage(canvas.width, canvas.height);

  68.     //WebGL是egret的Beta特性,默认关闭
  69.     if(false){// egret.WebGLUtils.checkCanUseWebGL()) {
  70.         context.rendererContext = new egret.WebGLRenderer(canvas);
  71.     }
  72.     else {
  73.         context.rendererContext = new egret.HTML5CanvasRenderer(canvas);
  74.     }

  75.     egret.MainContext.instance.rendererContext.texture_scale_factor = 1;
  76.     context.run();

  77.     var rootClass;
  78.     if(document_class){
  79.         rootClass = egret.getDefinitionByName(document_class);
  80.     }
  81.     if(rootClass) {
  82.         var rootContainer = new rootClass();
  83.         if(rootContainer instanceof egret.DisplayObjectContainer){
  84.             context.stage.addChild(rootContainer);
  85.         }
  86.         else{
  87.             throw new Error("文档类必须是egret.DisplayObjectContainer的子类!");
  88.         }
  89.     }
  90.     else{
  91.         throw new Error("找不到文档类!");
  92.     }
  93. }

  94. egret_h5.preloadScript = function (list, prefix) {
  95.     if (!egret_h5.preloadList) {
  96.         egret_h5.preloadList = [];
  97.     }
  98.     egret_h5.preloadList = egret_h5.preloadList.concat(list.map(function (item) {
  99.         return prefix + item;
  100.     }))
  101. }

  102. egret_h5.startLoading = function () {
  103.     var list = egret_h5.preloadList;
  104.     egret_h5.loadScript(list, egret_h5.startGame);
  105. }
复制代码
webflasher  初学乍练 | 2014-8-15 11:34:21
guoshaorui 发表于 2014-8-15 11:29
贴egret_loader.js的代码
  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 = {};

  28. egret_h5.prefix = "";

  29. egret_h5.loadScript = function (list, callback) {
  30.     var loaded = 0;
  31.     var loadNext = function () {
  32.         egret_h5.loadSingleScript(egret_h5.prefix + list[loaded], function () {
  33.             loaded++;
  34.             if (loaded >= list.length) {
  35.                 callback();
  36.             }
  37.             else {
  38.                 loadNext();
  39.             }
  40.         })
  41.     };
  42.     loadNext();
  43. }

  44. egret_h5.loadSingleScript = function (src, callback) {
  45.     var s = document.createElement('script');
  46.     if (s.hasOwnProperty("async")) {
  47.         s.async = false;
  48.     }
  49.     s.src = src;
  50.     s.addEventListener('load', function () {
  51.         this.removeEventListener('load', arguments.callee, false);
  52.         callback();
  53.     }, false);
  54.     document.body.appendChild(s);
  55. }

  56. egret_h5.startGame = function () {
  57.     var canvas = document.getElementById(egret.StageDelegate.canvas_name);
  58.     context = egret.MainContext.instance;
  59.     context.touchContext = new egret.HTML5TouchContext(canvas);
  60.     context.deviceContext = new egret.HTML5DeviceContext();
  61.     context.netContext = new egret.HTML5NetContext();


  62.     //设置屏幕适配策略
  63.     var container = new egret.EqualToFrame();
  64.     var content = egret.Browser.getInstance().isMobile ? new egret.FixedWidth() : new egret.NoScale();
  65.     var policy = new egret.ResolutionPolicy(container, content);
  66.     egret.StageDelegate.getInstance().setDesignSize(480, 800, policy);

  67.     context.stage = new egret.Stage(canvas.width, canvas.height);

  68.     //WebGL是egret的Beta特性,默认关闭
  69.     if(false){// egret.WebGLUtils.checkCanUseWebGL()) {
  70.         context.rendererContext = new egret.WebGLRenderer(canvas);
  71.     }
  72.     else {
  73.         context.rendererContext = new egret.HTML5CanvasRenderer(canvas);
  74.     }

  75.     egret.MainContext.instance.rendererContext.texture_scale_factor = 1;
  76.     context.run();

  77.     var rootClass;
  78.     if(document_class){
  79.         rootClass = egret.getDefinitionByName(document_class);
  80.     }
  81.     if(rootClass) {
  82.         var rootContainer = new rootClass();
  83.         if(rootContainer instanceof egret.DisplayObjectContainer){
  84.             context.stage.addChild(rootContainer);
  85.         }
  86.         else{
  87.             throw new Error("文档类必须是egret.DisplayObjectContainer的子类!");
  88.         }
  89.     }
  90.     else{
  91.         throw new Error("找不到文档类!");
  92.     }
  93. }

  94. egret_h5.preloadScript = function (list, prefix) {
  95.     if (!egret_h5.preloadList) {
  96.         egret_h5.preloadList = [];
  97.     }
  98.     egret_h5.preloadList = egret_h5.preloadList.concat(list.map(function (item) {
  99.         return prefix + item;
  100.     }))
  101. }

  102. egret_h5.startLoading = function () {
  103.     var list = egret_h5.preloadList;
  104.     egret_h5.loadScript(list, egret_h5.startGame);
  105. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

webflasher

初学乍练

积分: 5 帖子: 8 精华: 0

楼主热帖

小黑屋|京网文[2014]0791-191号|京ICP证150115号|Egret社区 ( 京ICP备14025619号 )

Powered by Discuz! X3.4 © 2001-2019 Comsenz Inc.

返回顶部