根据已知的宽度和高度计算最佳嵌入尺寸?
我正在尝试为我的游戏网站设计一个“网状样条”按钮。
其功能是调整游戏嵌入的大小,以最佳地填充我正在玩游戏的窗口。
到目前为止,我已经得到了一些可以正常工作的示例:
Sushi Cat 和 Squirrelfall 似乎都可以正常工作。
不幸的是,在使用 TimEmu
时,游戏尺寸太宽而无法适应窗户。
执行此操作的函数是带有一点 PHP 的 jQuery:
function game_resize(orig) {
dH = <?= $r['height'] ?>;
dW = <?= $r['width'] ?>;
maxH = $(window).height();
maxW = $(window).width();
nR = (maxH - 80) / dH;
if (orig) {
$('#gamebed').width(dW);
$('#gamebed').height(dH);
} else {
$('#gamebed').width(dW * nR );
$('#gamebed').height(dH * nR);
}
}
我只是无法专注于正确的检查以确保 div 游戏空间填充屏幕而不超出。我必须对纵横比做一些事情。
也许我必须离开键盘一段时间,然后再回到键盘上(有时这些东西会在休息后突然出现)。
任何人都可以“看到”这个问题的答案吗?我确信这是显而易见的。
I'm trying to work out a "Reticulate Splines" button for my gaming website.
The function of which is to resize the embed of a game to optimally fill the window I'm playing the game in.
So far I've got a few examples that work just right:
Sushi Cat and Squirrelfall both seem to work properly.
Unfortunately, when working on TimEmu
the game is sizing up too wide to fit into the window.
The function that does this is jQuery with a bit of PHP:
function game_resize(orig) {
dH = <?= $r['height'] ?>;
dW = <?= $r['width'] ?>;
maxH = $(window).height();
maxW = $(window).width();
nR = (maxH - 80) / dH;
if (orig) {
$('#gamebed').width(dW);
$('#gamebed').height(dH);
} else {
$('#gamebed').width(dW * nR );
$('#gamebed').height(dH * nR);
}
}
I just can't wrap my head around the right checks to ensure the div game space fills the screen without going over. I've got to do something about aspect ratio.
Maybe I've got to walk away from the keyboard for a bit and come back to it (sometimes this stuff just comes to you in a flash after a break).
Can anyone just "see" the answer to this one? I'm sure it's obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您能够接受基于 Flash 的解决方案,则可以将舞台的scaleMode 设置为 SHOW_ALL
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Stage.html#scaleMode
并将嵌入器的大小调整为整个区域。然后 Flash 会自动添加您要查找的边框。这当然需要您能够调整嵌入的 swf。
If you're able to accept a flash based solution, you could set the stage's scaleMode to SHOW_ALL
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Stage.html#scaleMode
and size the embedder to the full area. Flash will then automatically add the borders that you're looking for. This would of course require you to be able to adjust the embedded swf.