gpt4 book ai didi

javascript - 基本 Crafty 游戏填满移动设备上的整个屏幕

转载 作者:行者123 更新时间:2023-11-28 02:16:40 25 4
gpt4 key购买 nike

我正在尝试使用 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();

}

我尝试使用视口(viewport)元标记,但这不起作用crafty.js 网站上的入门游戏在移动设备上也存在同样的问题: http://buildnewgames.com/assets/article//introduction-to-crafty/tut_bng/index.html .

有什么解决办法吗?

最佳答案

我发现了问题(或者可能是一个功能)。 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;

我只是更喜欢让用户决定是否要缩放。

干杯

关于javascript - 基本 Crafty 游戏填满移动设备上的整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16289670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com