[0]图片裁剪,设置textrue的宽高后还是按照原始texteur裁剪,求解!!!

    var t = Laya.loader.getRes("res/main/bg/pt1.png") as Laya.Texture;
            let clipTexture : Laya.Texture = Laya.Texture.create(this.owner.scene.needImg.texture,this.ptConfig.Typesetting.x,this.ptConfig.Typesetting[i].y,this.ptConfig.Typesetting[i].width,this.ptConfig.Typesetting[i].height);
            let sp: Laya.Sprite = new Laya.Sprite();//创建精灵
            sp.name = this.ptConfig.Typesetting[i].id.toString();
            sp.graphics.drawTexture(clipTexture,0,0,this.ptConfig.Typesetting[i].width,this.ptConfig.Typesetting[i].height);//把截图绘制到精灵上
           
[/i][/i][/i][/i][/i][/i]
已邀请:

Laya_Fred

赞同来自:

您好,我这里在官网示例 摄像机--渲染到2DSprite 内使用drawTexture设置自定义宽高后是正常的,提供个示例吧,方便定位问题。

。我姓颜

赞同来自:

写了一个,麻烦大大帮忙看看!

Laya_Fred

赞同来自:

您好,您是想实现这样的效果吗?

1.png


如果是的话,在您创建texture的时候,使用texture.create()传入的参数,从0,0点开始,只截取了148,158绝对宽高的texture大小,所以下面drawtexture的时候就只有这一部分的texture。

2.png

 
在创建texture的时候,不进行裁剪的话直接设置源texture的宽高就可以,在drawtexture里面设置需要绘制的宽高。
let clipTexture : Laya.Texture = Laya.Texture.create(this.needImg.texture,0,0,this.needImg.width,this.needImg.height);

 

要回复问题请先

商务合作
商务合作