2013-04-29 106 views
1

我嘗試Crafty.js做一些基本的遊戲和它完美的作品在桌面瀏覽器,但填補了移動設備上的整個屏幕。在這裏我的網頁:基本狡猾的遊戲填滿整個屏幕上移動設備

<html> 
<head> 
    <title>Game</title> 
    <script src="/javascripts/crafty.js" type="text/javascript"> 
    </script> 
    <script src="/javascripts/homeGame.js" type="text/javascript"> 
</script> 
</head> 

<body style="margin:0 0"> 
    <div id="cr-stage"></div> 
</body> 
</html> 

,最後我的遊戲(homegame.js):

window.onload = function() { 

    Game = { 
    // Initialize and start our game 
    start: function() { 
    // Start crafty and set a background color so that we can see it's working 
    Crafty.init(480, 320); 
    Crafty.background('#2d3d4b'); 
    } 
} 

Game.start(); 

} 

我嘗試使用視meta標籤,但沒有奏效 同樣在狡猾的入門遊戲.js文件網站已經在移動設備上同樣的問題: http://buildnewgames.com/assets/article//introduction-to-crafty/tut_bng/index.html

任何想法如何解決它?

+0

嗯,你已經設置了寬度和高度在你的CSS ... – 2013-04-29 23:09:15

+0

我刪除了CSS(抱歉,這是我debuggin的一部分)。但無論如何,CSS設置爲700x400和iPad爲1024x768,這樣不應該填充整個屏幕 – 2013-04-29 23:29:17

回答

1

我發現這個問題(或者它可能是一個功能)。在crafty.js的4282線,有這麼一句話:

* If Crafty.mobile is equal true Crafty does some things under hood: 
    * ~~~ 
    * - set viewport on max device width and height 
    * - set Crafty.stage.fullscreen on true 
    * - hide window scrollbars 
    * ~~~ 
    * 
    * @see Crafty.viewport 
    */ 
    if (mobile) Crafty.mobile = mobile[0]; 

如果你對此有何評論上面的線,並與下面的一個替換它,它的工作原理

if (mobile) Crafty.mobile = false; 

我只是喜歡讓用戶決定是否他想放大或縮小。

乾杯

+4

而不是修改狡猾的JS核心,你可以在調用init前覆蓋值。設置在你的onload/domready事件處理程序'Crafty.mobile = FALSE'。 – howard10 2013-11-24 18:19:32