如何在PIXI.js中计算生成纹理的分辨率。 generateTexture(...)的文档需要一个分辨率的数字。
Doc:http://pixijs.github.io/docs/PIXI.Graphics.html#generateTexture
在以下示例中,将绘制具有特定宽度和高度的矩形。在我看来,分辨率将是宽度和高度相乘的像素数。
this._graphics.lineStyle(1, 0x012489, 1.0);
this._graphics.beginFill(0x696969, this.1.0);
this._graphics.drawRect(-(width/2.0), -(height/2.0), width, height);
this._graphics.endFill();
this.texture = this._graphics.generateTexture(width * height, PIXI.SCALE_MODES.DEFAULT);
答案 0 :(得分:0)
From the code it seems that what resolution sets, is not resolution, but the relative resolution, pratically this: https://pixijs.github.io/docs/PIXI.BaseTexture.html#resolution, so as it states: "the resolution of the texture for devices with different pixel ratios".
The default is 1, which is normal for desktop devices, the pixel ratio can be different on mobile devices. You should be able to get pixel ratio with this function (getPixelRatio): https://github.com/Hachitus/FlaTWorld/blob/master/src/components/map/core/utils/utils.js#L195 , but the function is not really battle-tested, though hasn't shown any issues in tests so far either.