[LayaAir 2.0]drawToTexture 绘制函数不工作呢

 
        let top_rect: Laya.Sprite = new Laya.Sprite();
        top_rect.x = 0;
        top_rect.y = 0;
        top_rect.size(100, 100);
        top_rect.graphics.drawRect(0, 0, 100, 100, "#0000FF", "#000000", 1); 
        Laya.stage.addChild(top_rect); 
        let rect_bottom: Laya.Sprite = new Laya.Sprite();
        rect_bottom.x = 0;
        rect_bottom.y = 0;
        rect_bottom.size(100, 100);
        rect_bottom.graphics.drawRect(110, 0, 100, 100, "#FF00FF", "#000000", 1); 
        Laya.stage.addChild(rect_bottom); 
        //将rect_bottom中的内容绘制到一个texture上面,再将整个texture绘制到
        //top_rect上面,显示出来两个的两个矩形应该是一个颜色啊?
        let t: Laya.Texture = rect_bottom.drawToTexture(100, 100, 0, 0);
        top_rect.graphics.drawTexture(t, 0, 0, 200, 100);
 
 
 
TIM截图20190730183415.png
已邀请:

宁远

赞同来自:

找到原因了,这个函数的drawToTexture的时候要传stage的坐标,好难理解

宁远

赞同来自:

        let tex = Laya.loader.getRes("res/atlas/test.png");
        let img = new Laya.Sprite();
        img.size(100,100);
        img.x = 400;
        img.y = 0;
        img.graphics.drawTexture(tex,0,0,100,100);
        //img.graphics.drawRect(0,0,50,50,"#000000","#FFFFFF",2);
        Laya.stage.addChild(img);
        
        //Laya.loader.getRes("res/atlas/test.png");
        //let texcpy:laya.resource.Texture = Laya.loader.getRes("res/atlas/test.png")
        let texcpy:laya.resource.Texture = img.drawToTexture(100,100,0,0);
        let copyimg:Laya.Sprite = new Laya.Sprite();
        copyimg.size(100,100);
        copyimg.pos(0,200);
        copyimg.graphics.drawTexture(texcpy,0,0,100,100);
        Laya.stage.addChild(copyimg);
 
这样的方式复制的图片也显示不出来
 

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作