[LayaAir 2.0]laya2.0 截图功能分享,直接截取屏幕上所有对象

laya2.0官方推荐的截图方法,drawToCanvas在截取3d场景时,出现了模型穿插的情况,原因是因为这个api在截取3d场景时,不是根据z顺序下去,而是根据在children中的先后顺序排列的,所以会出现截取2d场景都正常,但是3d场景错误的情况,尝试过多种方法后,下面提供一个简单的方法,能够直接将你所有看到的东西全部截取下载,测试小游戏正常可用
private static _sp: Laya.Sprite = null;
private static tempTexture2D: Laya.Texture2D;
private static tempTexture: Laya.Texture;
/**截图 */
public static drawScreenshot(width, height, x, y)
{
if (!SwitchHelper.screenDraw)
{
return null;

if (!this.tempTexture2D)
{
this.tempTexture2D = new Laya.Texture2D(system.width, system.height);
}
if (!this.tempTexture)
{
this.tempTexture = new Laya.Texture(this.tempTexture2D);
}
let cans = document.getElementById("layaCanvas");; 
Laya.timer.frameOnce(1, this, () =>
{
this.tempTexture2D.loadImageSource(cans, true);
}); 
return this.tempTexture;
}
已邀请:

怦然心动。

赞同来自:

你好,用了你的方法之后,发现两个问题,希望可以帮忙解决下
chrome 微信开发者工具 都没有问题。
在真机下会有2个问题
1 android下 canvas绘制赋值给sprite后 图像Y轴相反。(可以通过判断是否为安卓机型解决 )
2 ios下 截取后 赋值给sprite 没有反应。log里texture对象跟安卓下的texture对象没有区别。

要回复问题请先

商务合作
商务合作