Mer*_*lin 5 javascript canvas pixi.js
我正在使用Pixi.js作为渲染引擎,在Javascript中开展一个小项目.但是,我只发现了一些将画布缩放到完整窗口的方法,这些方法似乎最适合当前版本.但是,它有一个警告,因为它根据方向在侧面产生信箱.
是否可以通过Pixi避免使用信箱?
这是我到目前为止的代码,因为它与缩放有关:
var application = null;
var GAME_WIDTH = 1060;
var GAME_HEIGHT = 840;
var ratio = 0;
var stage = null;
application = new PIXI.Application(
{
width: GAME_WIDTH,
height: GAME_HEIGHT,
backgroundColor: 0x00b4f7,
view: document.getElementById("gwin")
});
stage = new PIXI.Container(true);
window.addEventListener("resize", rescaleClient);
function rescaleClient()
{
ratio = Math.min(window.innerWidth / GAME_WIDTH, window.innerHeight /
GAME_HEIGHT);
stage.scale.x = stage.scale.y = ratio;
application.renderer.resize(Math.ceil(GAME_WIDTH * ratio), Math.ceil(GAME_HEIGHT * ratio));
}
Run Code Online (Sandbox Code Playgroud)
我的目标是实现与Agar.io/Slither.io类似的全屏/窗口效果,但是我还没有找到一种方便的方法.似乎有一些使用Pixi来实现这一目标的例子,但代码通常是封闭源代码,并且它们似乎使用外部工具,如Ionic和Phonegap.
我终于找到了答案。我已经接近正确的轨道,但还需要应用一些东西。
application.renderer.view.style.position = "absolute";
application.renderer.view.style.display = "block";
application.renderer.autoResize = true;
application.renderer.resize(window.innerWidth, window.innerHeight);
Run Code Online (Sandbox Code Playgroud)
这在内部设置了一些额外的东西,同时对调整大小脚本进行了微小的修改......
ratio = Math.min(window.innerWidth / GAME_WIDTH, window.innerHeight / GAME_HEIGHT);
stage.scale.x = stage.scale.y = ratio;
renderer.resize(window.innerWidth, window.innerHeight);
Run Code Online (Sandbox Code Playgroud)
正确配置,以便相关渲染器窗口现在填充屏幕,而不会挤压内容。
这并不容易发现。很多教程只是把它留在前半部分,并假设这就是人们想要做的。
| 归档时间: |
|
| 查看次数: |
212 次 |
| 最近记录: |